我有一个继承自 Action 的类 InheritAction。现在我想做的是为 PositiveIntegerField 提供不同的选择。我知道我们不能覆盖 django 中的类属性。但是有没有办法做到这一点。提前致谢
ACTION_TYPE = (
(1, 'Approve'),
(2, 'Reject'),
(3, 'More Information Required'),
(4, 'Status Update')
)
class Action(models.Model):
type = models.PositiveIntegerField(choices=ACTION_TYPE)
INHERIT_ACTION_TYPE = (
(1, 'Approve'),
(2, 'Reject'),
(3, 'More Information Required'),
(4, 'Status Update')
)
class InheritAction(Action):
pass
我试过这样做......
InheritAction._meta.get_field('type).choices = INHERIT_ACTION_TYPE
但是报错...
AttributeError: can't set attribute