On Sep 24, 12:52 am, "Daniele Procida" <dani...@apple-juice.co.uk> wrote: > Don't I need to run some sort of save for those? Otherwise, what happens > to the attributes once I have set them?
Sorry, I responded too hastily and erroneously. Here's the proper, longer explanation. Assume the following models: class Referee(models.Model): name = models.CharField(max_length=255) class Referrer(models.Model): name = models.CharField(max_length=255) references = models.ManyToManyField(Referee) It is evident that a many-to-many relation (references) can be saved only after the object that has the relation (Referrer) is warranted to have a value for it's primary key field, as "behind the scenes, Django creates an intermediary join table to represent the many-to- many relationship" (quote from http://docs.djangoproject.com/en/dev/ref/models/fields/#manytomanyfield ) So, given a obj = Referrer("foo"), updating its many-to-many field can happen only after obj.save() returns (this is documented in http://www.djangoproject.com/documentation/models/many_to_many/ ). If you are not able to call obj.save() and then manually update the fields, the only chance is to use a signal. Unfortunately, Django core does not currently fire any signals on ManyToManyField changes. There's a ticket, http://code.djangoproject.com/ticket/5390 , that has a patch with a solid implementation of that particular signal. It also includes tests that demonstrate how to use the signal (see http://code.djangoproject.com/attachment/ticket/5390/complete-patch.diff ). So, unless the manual way works for you, I recommend you apply the patch. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---