我有简单的代码,bug不起作用!
向未调用的内容添加标记后
tag_update_count_use
哦!
型号。py公司
class Tag(models.Model):
count_use = models.PositiveIntegerField(_('count use'), default=0)
def update_count_use(self, delta):
self.count_use += delta
self.save(update_fields=['count_use'])
class Content(models.Model):
tags = models.ManyToManyField('Tag', blank=True, verbose_name=_('tags'))
信号。py公司
from django.db.models.signals import m2m_changed
from django.dispatch import receiver
@receiver(m2m_changed, sender=Content.tags)
def tag_update_count_use(sender, **kwargs):
print(kwargs)
return kwargs
__init\uuuu。py公司
default_app_config = 'content.apps.ContentConfig'
应用程序。py公司
class ContentConfig(AppConfig):
name = 'content'
verbose_name = _('content')
def ready(self):
import content.signals
根据
https://docs.djangoproject.com/en/dev/ref/signals/#m2m-changed
我将代码更改为:
@receiver(m2m_changed, sender=Content.tags.though)
但我收到以下错误:
AttributeError: 'ManyToManyDescriptor' object has no attribute 'though'