Your instance is probably not yet saved to the database, so the m2m-related
objects don't know which instance to connect to. There's problem something
wrong in your save() method. I often use "assert False, some_var" to check
if at some point the variable is already set or not.

And I get the same problem as you so many times that forms have become the
thing I hate the most about Django, even though my lack of knowledge is the
one to be blamed, not the framework.


Cheers,
AT

On Thu, Aug 18, 2011 at 5:48 AM, Tom Evans <tevans...@googlemail.com> wrote:

> 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.
>
>

-- 
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.

Reply via email to