3

If I have some choices variable:

In [1]: from model_utils import Choices

In [2]: CHOICES = Choices(
   ...:         (1, 'somekey', 'The long title'),
   ...:     )

In [3]: CHOICES[1]
Out[3]: 'The long title'

How to retrieve somekey key from it? This answer doesn't work for me.

In [10]: {v: k for k, v in dict(CHOICES).iteritems()}
Out[10]: {'The long title': 1}
Danil
  • 4,781
  • 1
  • 35
  • 50

1 Answers1

3

the solution is:

In [11]: {v: k for k, v in CHOICES._identifier_map.items()}
Out[11]: {1: 'somekey'}
Danil
  • 4,781
  • 1
  • 35
  • 50