django manytomanyfield .add() method

后端 未结 2 1792
难免孤独
难免孤独 2021-01-05 12:57

Suppose i have :

class Album(models.Model):
    photos = models.ManyToManyField(\'myapp.Photo\')
    photo_count = models.IntegerField(default = 0)

class P         


        
2条回答
  •  借酒劲吻你
    2021-01-05 13:22

    You can use django's signals and write a signal handler that will increment the counter using the m2m_changed signal:

    https://docs.djangoproject.com/en/dev/ref/signals/#m2m-changed

提交回复
热议问题