I got some help on the Django IRC channel: The anwser is that django save m2m relationship in the admin by calling 'clear' on it, then setting it. I means that the form destroy any attached data to the object then add the ones in you entered in the admin.
It works outside the admin because we don't use the admin form that clear the m2m relationship. The reason it works for tags in the admin is that the tagging application doesn't use m2m but emulate it by placing a TaggedItem object with a foreign key to a tag and to your model with a generic relation. Plus it's an inline field inclusion. I think a possible solution is to create a custom admin form and add the site from here. On 13 mai, 00:03, ksamuel <info.ksam...@gmail.com> wrote: > I overrided the save method of one of my model to it sync its sites > with its parent sites: > > def save(self, *args, **kwargs): > > ret = models.Model.save(self, *args, **kwargs) > > if self.id: > > for site in self.parent.sites.all(): > self.sites.add(site.id) > > This code work, except when you save the object in the admin. Using > PDB, I can see that self.parent.sites.all() return something at the > end of send. But right after, the relations disapears. I'm not > (willingly at least) using transactions. > > More details > here:http://stackoverflow.com/questions/5982347/why-is-adding-site-to-an-o... -- 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.