Django类方法目前已被覆盖

时间:2018-06-03 11:41:38

标签: django django-models

当我尝试在命令行中运行python manage.py makemigrations

时,这是错误
ERRORS:
asking.Question: (models.E020) The 'Question.check()' class method is currently overridden by <function BaseManager.check at 0x7f0f104889d8>.

这是[{1}}中的Question课程:

models.py

这是BaseModel类:

class Question(BaseModel):
    content = models.CharField(max_length=250)
    answer = models.TextField("answer", blank=True, null=True)
    answerer = models.ForeignKey(
        User,
        on_delete=models.CASCADE,
        related_name="questions"
    )

    def __str__(self):
        return self.content

我正在使用Django 2.0.5版

2 个答案:

答案 0 :(得分:1)

我认为问题是您的BaseModel来自SoftDeletableManager而不是SoftDeletableModel

例如改为:

class BaseModel(SoftDeletableModel, TimeStampedModel, models.Model):

    class Meta:
        abstract = True

答案 1 :(得分:0)

应将经理设置为模型属性

from django.db import models
from model_utils.models import SoftDeletableManager, TimeStampedModel


class BaseModel(TimeStampedModel, models.Model):

    objects = SoftDeletableManager()

    class Meta:
        abstract = True