On Thu, 2008-10-09 at 11:13 -0700, Aljosa Mohorovic wrote: > i have a problem that ManyToManyField in post_save signal doesn't seem > to be updated, i get wrong row count although i get right row count on > response/web page. > is this some kind of caching that i need to specify not to cache or > something similar? > part of code with problem: > --- > def sorted_photos_change(sender, **kwargs): > gallery = kwargs['instance'] > # prints number of photos before change instead current number of > photos > print gallery.photos.count() > [...] > > post_save.connect(sorted_photos_change, sender=Gallery) > --- > > have manytomany fields for signal instance been committed when > post_save signal is emitted?
You don't say how the many-to-many objects are being added, but be aware that the post_save signal is raised from Model.save(). So for something like forms, it is emitted before any related fields are added (since a Gallery needs to be saved so that is has a primary key value before it can be stored in a many-to-many table). Therefore, your code is returning the right answer for the moment it is run. There's a long-standing ticket open (#5390 and possibly one or two others) about adding a signal to related managers. I've started thinking about that -- it's not entirely trivial, since we also want to reorganise the internals of those classes a bit to make things easier in a number of ways. But it's certainly something that's got a good chance of being in 1.1, so stay tuned. Regards, Malcolm --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---

