How to get key from model_utils triple Choices?

930 Views Asked by At

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}
1

There are 1 best solutions below

0
On BEST ANSWER

the solution is:

In [11]: {v: k for k, v in CHOICES._identifier_map.items()}
Out[11]: {1: 'somekey'}