I have an object that has a m2m relation, and I would like to populate it after saving.
The problem is that the signal is triggered, but the command add doesn't work. I did try the same steps using python shell, and it worked fine.
class Event(models.Model):
name = models.CharField(max_lenght=40)
location = models.ManyToManyField('Location')
class Location(models.Model):
address = models.CharField(max_lenght=60)
@receiver(post_save, sender=Event)
def populate_location(sender, instance, **kwargs):
instance.locations.add(*Locations.objects.all())
Any hint?