On Thu, Sep 24, 2009, Daniele Procida <dani...@apple-juice.co.uk> wrote:

>>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, 
>
>Thanks - I have saved the object, with super(Event, self).save() in the
>save() function, and then updated the fields.
>
>However: I still need to save those changed fields to the database. If I
>call self.save, I end up recursing indefinitely. If I call super(Event,
>self).save() again, it appears to save nothing.

I understand now that it is not necessary to save changes to m2m fields
- they are saved as soon as they are made, which makes everything much
simpler.

So my save() method for the Event model is now:

def save(self):
    # do some stuff for the other fields
    super(Event, self).save()
    if not self.enquiries.all():
        self.enquiries = set()
        for person in self.parent.enquiries.all():
            self.enquiries.add(person)
    
Now if I print self.enquiries.all() and self.parent.enquiries.all(),
they appear to be the same. But, a test with:

    if self.parent.enquiries.all() == self.enquiries.all():

suggest they are not.

At any rate, if they have been changed, the changes don't make it to the
database.

I'm clearly missing some important thing, but I can't work out what it is.

Daniele


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to