On Thu, Aug 18, 2011 at 4:44 AM, Shawn Milochik <sh...@milochik.com> wrote: > I have some code that modifies related items when a model is saved. I've > tried this by both using a post_save signal and by putting the code directly > in a save() override. > > When I save an instance in the Django admin, it never works. > When I save an instance in ./manage.py shell it always works. > > Why would this be? > > For instance, if my code (in the save override) is this: > > self.some_m2m_field.clear() > self.some_m2m_field.add(this_thing) > > Then if I go into the admin and save the instance, this_thing is not > attached to the instance. But if I do a .save() in the shell and check it > has been assigned. > > I assume I'm missing something fundamental about this. > > Thanks, > Shawn
I've never encountered this Shawn, but the primary difference between those two is that saving in the admin will go through a ModelForm. Does the admin site use frm.save(commit=False) and then run frm.save_m2m()? frm.save_m2m() would definitely be run after both an overwritten save() and a post_save hook. Worth a thought. Cheers Tom -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.