gpt4 book ai didi

python - Django ORM对象没有属性 '_set'

转载 作者:行者123 更新时间:2023-11-30 23:21:33 25 4
gpt4 key购买 nike

我假设 Django 自动为我创建了 _set 但出现以下错误。

for dep_badge in self.badge.badge_set.all():
AttributeError: 'Badge' object has no attribute 'badge_set'

型号:

class Badge(RewardBase):
"""
Represents a Badge.
"""
name = models.CharField(max_length=60, help_text="Name of the badge")
description = models.TextField(max_length=150)
reputation_value = models.IntegerField(help_text="Value given in accumulate reputation", default=0)
reputation_prerequisite = models.IntegerField(help_text="Point value needed to obtain", default=0)
difficulty_level = models.IntegerField(choices=STATUS_TYPES, default=STATUS_EASY,
help_text="Badge difficulty")


class Award(RewardBase):
"""
Representation of a badge awarded to a user.
"""

description = models.CharField(max_length=100, choices=STATUS_TYPES, default=STATUS_GENERAL)
value = models.IntegerField(default=0)
read = models.BooleanField(default=False, help_text="Has the user read this?")
created = models.DateTimeField(blank=True, null=True, editable=False)
hidden = models.BooleanField(default=False)

user = models.ForeignKey(settings.AUTH_USER_MODEL)
badge = models.ForeignKey("Badge")


def save(self, *args, **kwargs):


super(Award, self).save(*args, **kwargs)


for dep_badge in self.badge.badge_set.all():
dep_badge.check_prerequisites(self.user, sel

f.徽章, self )

最佳答案

徽章没有徽章集。其自身没有外键。也许你指的是award_set?

关于python - Django ORM对象没有属性 '_set',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24875243/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com