2

Suppose I have the following Django (3.2) code:

class AType(models.IntegerChoices):
    ZERO = 0, 'Zero'
    ONE = 1, 'One'
    TWO = 2, 'Two'

a = AType.ZERO

How do I get "Zero" (the string associated with a)?

This is very similar to this question, except here we only have the IntegerChoices object, and not an associated model object.

dfrankow
  • 20,191
  • 41
  • 152
  • 214

1 Answers1

3

You can use .label:

>>> a = AType.ZERO
>>> a.label
'Zero'
Brian Destura
  • 11,487
  • 3
  • 18
  • 34