Thanks Roald, By "b_set" do you mean that I have to create a queryset instance? If so, I should place it just above the function?
On May 26, 7:21 pm, Roald <downa...@gmail.com> wrote: > On May 26, 11:07 am, piker <da...@allnatives.com.au> wrote: > > > I have a model class (A) that has a M2M field with its relationship > > to another model (B). When I save an instance of model class (A) I > > want to automatically update a BooleanField in all the many, related > > model(B) instances at the same time. Is the right way to do this > > through a Model Method? If so, how should I reference across the M2M > > relationship? Any advice appreciated as I can't seem to find an answer > > to this specific problem. > > Something like the code below (untested). If you want to update > depending on the current value of bool_field, have a look > athttps://docs.djangoproject.com/en/dev/topics/db/queries/#filters-can-.... > > class A(models.Model): > ... > def save(self, *args, **kwargs): > super(A, self).save(*args, **kwargs) > self.b_set.update(bool_field=True) > > Cheers, Roald -- 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.