我有一个与 Campaign 有 ManyToManyField 关系的 Charity 模型,如下所示:
class Charity(models.Model):
name = models.CharField(max_length=200)
description = models.TextField(blank=True,null=True)
tag_line = models.CharField(max_length=160, blank=True,null=True)
campaigns = models.ManyToManyField(Campaign, related_name='campaign_charity')
...
ManyToManyField 工作正常,并且campaigns.all() 返回与慈善机构相关的正确活动集。当我尝试使用 object.charity_set 获取对象的反向集时,出现以下错误:
Traceback (most recent call last):
File "<console>", line 1, in <module>
AttributeError: 'Campaign' object has no attribute 'charity_set'
知道为什么吗?谢谢!