If I understand right, the problem is that you want the signal after all related fields are already saved. If so, this is exactly the problem I have too. You see, when you have such a relation (and, for example, edit the parent object with inlined related objects from the admin page, Django _has to_ save the parent object first, and only then it saves the related objects (you can verify it by adding print statements to your save methods or handlers and running the dev server from terminal). The reason is that when you initially create the object, related objects have to link to the existing object, so the parent object is saved before them.
On Jul 13, 9:27 pm, Ryan K <[email protected]> wrote: > Recently I've been trying to get answers about the post_save signal > behavior and perhaps have been asking too much of readers without > narrowing down the problem enough myself. So here is my effort to ask > a rather straightforward question: > > The code that connects to the post_save signal, according to the > signal docs, is passed three objects and I am only concerned about > one: the instance that was saved. Now this instance has a > ManyToManyField and what I am finding out according to be debugging is > that the instance's ManyToMany field is NOT being updated after save > is called. > > So, for example, when the signal calls the handler (this is being done > via the admin interface but it shouldn't matter) and I check > instance.manytomanyfield, it does not show the most recent changes. > What is the best way to "force" the update of the table so I can get > accurate data from the ManyToMany field? Even if I explicitly do > something like this: > > def __init__(self, sender, instance): > self.sender = sender > self.instance = sender.objects.select_related().get > (id=instance.id) > > What seems like cached data is being when I test: > > self.instance.manytomanyfield.all() > > Can anyone help with this behavior? > > Cheers, > Ryan --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---

