有可能得到IntegerChoices的名字吗



我有像这个一样的IntegerChoices

class Action(models.IntegerChoices):
SYSTEM_START = 1
SYSTEM_STOP = 2

模型将其作为成员

class ActionLog(BaseModel):
log_action = m.PositiveSmallIntegerField(
choices=Action.choices,null=False)
def action_name(self):
// can I get the name such as SYSTEM_START here?

那么我想在模型的action_name函数中返回可读的名称。

有可能吗??或者我不应该使用models.IntegerChoices?

如果是,在这种情况下应该使用什么?

self.get_log_action_display()将为您提供可读的名称。将log_action替换为任何型号选择字段以获得显示名称。

最新更新