On Sat, 2006-07-08 at 17:49 +0000, william wrote: > I've been trough the save() as documented here: > http://code.djangoproject.com/wiki/RemovingTheMagic#Overridingsaveanddeletemodelmethods > > But, this does not work for fields having a ManyToMany relation. > If you take the example with "publication" and "article" as described > here: http://www.djangoproject.com/documentation/models/many_to_many/ > > If you put the following into the "Article" class: > def save(self): > print "Before",self.publications.all() > super(Article, self).save() > print "after",self.publications.all() > > You'll see that you'll always see the same result before and after the > save. > (standard fields are yet working correctly) > It seems that the manytomany related data are saved after the complete > execution of save(). > I'm using revision 3275 > In my case this is annoying.
Related items (the things being saved into the many-to-many relation) are not saved as part of a model's save method, as you have discovered. Instead, the Add- and ChangeManipulators save the many-to-many items later. In fact, for adding a new item, this is basically required, because you need to know the new instance's primary key value before you can save a reference to it in the m2m join table -- and that value does not necessarily exist before it is saved to the database. At the moment, any workaround is going to involve custom manipulators, I suspect (although I may be missing something obvious). We might be able to come up with something a bit nicer with the upcoming manipulator refactoring that is on the table. This does come up from time to time when somebody wants to take action based on a new relationship being created. So you're not on the fringe here by wanting this. Sorry, not much encouragement there except to say it's a known problem (well, at least, I consider it a "problem"). Maybe somebody smarter than me can suggest an easy solution at the moment *shrug*. 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 django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~----------~----~----~----~------~----~------~--~---