[Fixed]-Set value in related model with ManyToManyField

1👍

✅

Firstly, your get_all_foo method is incredibly inefficient, potentially causing thousands of separate database calls. Replace it with:

return ';'.join(D.objects.filter(c__b__a__=self).values_list('foo'))

You can use the same principle to update the D objects from A:

D.objects.filter(c__b__a__=self).update(foo=value)

Leave a comment