Admin is still annoying regarding model save(), and model post_save signals.

21 views
Skip to first unread message

Luis Masuelli

unread,
Jan 12, 2016, 10:37:37 AM1/12/16
to Django users
If you want to perform additional logic when you save your model...
   
class MyModel(models.Model):

   
#...

   
def save(self, *args, **kwargs):
       
self.a_rel_model_set.add(O)
       
super(MyModel, self).save(*args, **kwargs)
       
self.another_rel_model_set.add(O2)

Or similar login in pre_save and post_save signals, since they are many2many fields, they will be overriden on an admin form, since the form.save_m2m is called after the model save, and whatever changes I do on those signals, will be wiped out.

The logic I had to put it in log_change (ModelAdmin method). I don't know whether it is the appropriate method, but is the first method executed after model saving. Is it the appropriate method for that? Admin post-save logic... or should we have an additional method in the admin for that?

Luis Masuelli

unread,
Jan 12, 2016, 10:38:12 AM1/12/16
to Django users
Notes: This is only annoying when the logic involves many2many fields.
Reply all
Reply to author
Forward
0 new messages