I have IntegerChoices
like this
class Action(models.IntegerChoices):
SYSTEM_START = 1
SYSTEM_STOP = 2
and model has this as the member
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?
then I want to return the readable name in action_name
function of model.
Is it possible?? or I should not use models.IntegerChoices?
If so what should be used in this case?
CodePudding user response:
self.get_log_action_display()
will give you the readable name. Substitute log_action
for any model choice field to get the display name.