3

Is it possible to use django-polymorphic package and have a CharField in the parent class and change the "choices" depending on the children classes?

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)

I thought I would be able to override the original status in the parent class but it looks like I cannot have duplicate fields.

"Local field 'status' in class 'Circle' clashes with field of the same name from base class 'Shape'."

I want to also be able to list the status on the admin page.

Aero Chocolate
  • 1,477
  • 6
  • 23
  • 39

0 Answers0