更改Django-Polymorphic包中的子类的“选择”

时间:2019-01-24 07:24:22

标签: python-2.7 polymorphism django-1.11 django-polymorphic

是否可以使用django-polymorphic包并在父类中具有CharField并根据子类更改“选择”?

Ex)

class Shape(PolymorphicModel):
    name = models.CharField(max_length=255)
    status = models.CharField(max_length=255) # Will be modified per child class

CIRCLE_CHOICES = (("active", "Active"), ("ready","Ready To Go"), ("inactive","Deactive"))

class Circle(Shape):
    status = models.CharField(max_length=255, choices=CIRCLE_CHOICES)

SQUARE_CHOICES = (("steady", "Steady"), ("inactive","Inactive"), ("ready","Ready"))

class Square(Shape):
    status = models.CharField(max_length=255, choices=SQUARE_CHOICES)

我认为我可以覆盖父类中的原始状态,但是看起来我不能有重复的字段。

“类'Circle'中的本地字段'status'与基类'Shape'中具有相同名称的字段发生冲突。”

我还希望能够在管理页面上列出状态。

0 个答案:

没有答案