I have a model Location with m2m relation with Place and School
Each time places field is changed I want to set all existing schools to Location
from django.db.models.signals import m2m_changed
class Location(model.Model):
places = models.ManyToManyField(Place, related_name='locations')
schools = models.ManyToManyField(School, related_name='locations')
def places_changed(sender, instance, **kwargs):
instance.schools = School.objects.all()
print(instance.schools.all())
m2m_changed.connect(places_changed, sender=Location.places.through)
print(instance.schools.all()) - prints all school objects, but nothing saved - db is empty.
Please help) Thx for advices!