我想修改 STRUCTURE_CHOICES 以便它可以反映到结构字段选择中。
类 AbstractProduct(models.Model):
...
STRUCTURE_CHOICES = (
(STANDALONE, _('Stand-alone product')),
(PARENT, _('Parent product')),
(CHILD, _('Child product'))
)
...
structure = models.CharField(
_("Product structure"), max_length=10, choices=STRUCTURE_CHOICES,
default=STANDALONE)
...
类产品(抽象产品):
...
STRUCTURE_CHOICES = (
(STANDALONE, _('Stand-alone product')),
(PARENT, _('Parent product')),
(CHILD, _('Child product')),
(NEW_CHOICE, _('New Choice'))
)
...
我尝试以这种方式进行操作,但没有成功:
类产品(抽象产品):...
def __init__(self, *args, **kwargs):
self.STRUCTURE_CHOICES = (
(STANDALONE, _('Stand-alone product')),
(PARENT, _('Parent product')),
(CHILD, _('Child product')),
(NEW_CHOICE, _('New Choice'))
)
return super(Product, self).__init__(*args, **kwargs)
...