I have defined a Save
method in my model
for the order
fields.
Now, when I do some manipulations with the Order
field in View
and call save()
- I save twice - in View
save() and Model
save().
Because of this, the problem! How to solve this problem? How to make Save
work only when creating a model object? And don't work save
when I save()
in Views
def save(self, *args, **kwargs):
model_class = type(self)
last_item = model_class.objects.order_by('-order').first()
if last_item is not None:
self.order = last_item.order += 1
super().save(*args, **kwargs)