2
我有一個可以分配給模型AttributeError的:「ManyToManyDescriptor」對象有沒有屬性「所有」 - Django的
我打過電話來得到什麼團體的響應也該員工屬於許多其他組工作人員模型但我不斷收到錯誤。
有人能請我幫忙嗎? 用戶模型
class Staff(Model):
groups = ManyToManyField(Group,
related_name="%(class)ss",
related_query_name="%(class)s",
blank=True)
class Group(Model):
creator = ForeignKey(Employer,
on_delete=CASCADE,
related_name="%(class)ss",
related_query_name="%(class)s")
group_name = CharField(max_length=256, unique=True)
created_at = DateTimeField(auto_now_add=True)
我已經嘗試了一些方法,如
staff = Staff.objects.filter(pk=1)
groups = staff.group.all()
或 groups = staff.group_set.all()
或 groups = staff.group.filter()
,而且我不記得一些其他的方式,但我不斷獲取錯誤。
預先感謝
它是組。所以make groups = staff.groups.all() – sebb
@sebb我會得到像'AttributeError'這樣的錯誤:'QuerySet'對象沒有屬性'groups'' – Dora