我希望这个领域"更新"只要将M2M关系添加到"标记"就可以在标记模型中触发在电影中。
我已尝试过,但错误告诉我:Movie matching query does not exist
class Tag(models.Model):
name = models.CharField("Name", max_length=5000, blank=True)
updated = models.DateTimeField(auto_now=True)
class Movie(models.Model):
title = models.CharField("Title", max_length=10000, blank=True)
tag = models.ManyToManyField('Tag', blank=True)
updated = models.DateTimeField(auto_now=True)
def save(self, *args, **kwargs):
orig = Movie.objects.get(pk=self.pk)
for t in self.tag.exclude(pk__in=orig.tag.values_list('pk', flat=True)):
t.save()
super(Movie, self).save(*args, **kwargs)
我也尝试过使用m2m_chagned
def movie_changed(sender, **kwargs):
# Do something
pass
m2m_changed.connect(movie_changed, sender=Movie.tags.through)
然而,这也给了我"电影"没有定义。