我在和through
之间有一个用于 ManyToManyField 的自定义中介模型:Wishlist
Product
class Product(models.Model):
name = models.CharField(max_length=255)
created = models.DateTimeField(auto_now_add=True)
class Meta:
ordering = ('-created', )
def __unicode__(self):
return self.name
class Wishlist(models.Model):
user = models.ForeignKey(User)
name = models.CharField(max_length=255)
created = models.DateTimeField(auto_now_add=True)
products = models.ManyToManyField(Product, through='WishlistProduct', null=True, blank=True)
class Meta:
ordering = ('-created', )
def __unicode__(self):
return self.name
class WishlistProduct(models.Model):
wishlist = models.ForeignKey(Wishlist)
product = models.ForeignKey(Product)
created = models.DateTimeField(auto_now_add=True)
class Meta:
ordering = ('-created', )
def __unicode__(self):
return u'%s in %s' % (self.product.name, self.wishlist.name)
和一个m2m_changed
信号:
@receiver(m2m_changed, sender=Wishlist.products.through, dispatch_uid='m2m_changed_wishlist_products')
def m2m_changed_wishlist_products(sender, instance, action, *args, **kwargs):
print(sender)
print(action)
m2m_changed
信号不通,为什么?
但是post_save
WishlistProduct 的信号将被触发。