Sorted it out, for anyone else who is wondering..
This works:
class A(models.Model):
...
def save(self, *args, **kwargs):
super(A, self).save(*args, **kwargs)
self.b.all().update(bool_field=True) #note self.b.all()
Thanks again Roald for pointing me in the right direction.Cheers.
On May 26, 7:58 pm, piker <[email protected]> wrote:
> 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 <[email protected]> wrote:
>
>
>
>
>
>
>
> > On May 26, 11:07 am, piker <[email protected]> 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 [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.