Django错误:“与相关字段发生冲突的访问者”

时间:2013-05-07 19:26:02

标签: python django django-models

当我运行“python manage.py runserver”时,会打印以下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

在games / transcription / models.py中:

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

有什么建议吗?

1 个答案:

答案 0 :(得分:1)

你有两个叫做治疗的模特。虽然OfferTreatment是抽象的,但治疗的共享版本却不是。您应该将其标记为抽象,并将其重命名为BaseTreatment。

或者,您可能想要转录。处理成代理模型。