Re: How to update a ManyToManyField in a model's custom save method

2009-09-24 Thread Brian McKeever
The presave signal passes the instance of the updated object to the signal automatically, so your code should work with minimal modifications. Try this: from django.db.models.signals import post_save def member_check(sender, **kwargs): if Project.objects.filter(id__exact=self.id).count():

Re: How to update a ManyToManyField in a model's custom save method

2009-09-24 Thread Daniele Procida
On Wed, Sep 23, 2009, M Godshall wrote: > >I have a Project model with a ManyToManyField called "members" to keep >track of members of a project. Whenever the model is updated, I need >to check if certain members need to be removed from or added to the >m2m field.

Re: How to update a ManyToManyField in a model's custom save method

2009-09-24 Thread Godshall
I think i tried a postsave signal a while back without luck, but I'll give it another shot. In order to know which users to add to or remove from the members field I have to process the data in the save method itself. Can you show me how I could pass a list of users to remove and add to the

Re: How to update a ManyToManyField in a model's custom save method

2009-09-23 Thread Brian McKeever
Try using a postsave signal. It'll automatically trigger your method upon saving a Project. http://docs.djangoproject.com/en/dev/topics/signals/#receiver-functions Basically, all you'd need is: from django.db.models.signals import post_save def member_check(sender, **kwargs): #your code

How to update a ManyToManyField in a model's custom save method

2009-09-23 Thread M Godshall
I have a Project model with a ManyToManyField called "members" to keep track of members of a project. Whenever the model is updated, I need to check if certain members need to be removed from or added to the m2m field. The most logical place to do this is in the model's custom save method, but