1

当我运行“python manage.py runserver”时,会打印 4 次以下 2 条错误消息:

transcription.treatment: Accessor for field 'treatment_ptr' clashes with related field 'Treatment.treatment'. Add a related_name argument to the definition for 'treatment_ptr'.
transcription.treatment: Reverse query name for field 'treatment_ptr' clashes with related field 'Treatment.treatment'. Add a related_name argument to the definition for 'treatment_ptr'.

下面是我的代码。在 shared/models.py 中:

class Treatment(models.Model):
    code = RandomCharField(length=6)
    experiment_id = models.CharField(max_length = 10, null = True)


    base_pay = models.PositiveIntegerField(default=20)

    def was_started_recently(self):
        expiry_time = timedelta(minutes = 5)
        if datetime.now() - self.time_started < expiry_time:
            return True

class OfferTreatment(Treatment):
    max_offer_amount = models.PositiveIntegerField(default=50)
    increment_amount = models.PositiveIntegerField(default=5)

    def offer_choices(self):
       return range(0, self.max_offer_amount + 1, self.increment_amount)

    def is_valid_offer(amount):
        return amount in self.offer_choices()

    class Meta:
        abstract = True

在游戏/转录/models.py 中:

class Treatment(shared.models.OfferTreatment):
    short_name = 'tr'
    long_name = 'Transcription'

有什么建议么?

4

1 回答 1

1

您有两个模型,称为治疗。尽管 OfferTreatment 是抽象的,但 Treatment 的共享版本却不是。您可能应该将其标记为抽象,并将其重命名为 BaseTreatment 之类的名称。

或者,您可能希望将transcription.Treatment 转换为代理模型。

于 2013-05-08T10:27:14.780 回答