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():
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.
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
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
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
5 matches
Mail list logo