From cd09a723d4de6a8a221a80f29293f00e34ab990f Mon Sep 17 00:00:00 2001 From: Sergey Gordeychuk Date: Sun, 20 Aug 2023 22:30:51 +0300 Subject: [PATCH] Fix for getattr error in the admin --- adminsortable2/admin.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/adminsortable2/admin.py b/adminsortable2/admin.py index 664d8ba..5647c30 100644 --- a/adminsortable2/admin.py +++ b/adminsortable2/admin.py @@ -485,10 +485,11 @@ def save_new(self, form, commit=True): """ obj = super().save_new(form, commit=False) - order_field_value = getattr(obj, self.default_order_field, None) - if order_field_value is None or order_field_value >= 0: - max_order = self.get_max_order() - setattr(obj, self.default_order_field, max_order + 1) + if self.default_order_field: + order_field_value = getattr(obj, self.default_order_field, None) + if order_field_value is None or order_field_value >= 0: + max_order = self.get_max_order() + setattr(obj, self.default_order_field, max_order + 1) if commit: obj.save() # form.save_m2m() can be called via the formset later on