Django: How to get list of choices of choice field

I have Choices:

all_choices= Choices(
        ('val1', _("val1 text")),
        ('val1', _("val2 text")),
        ('val3', _("val3 text")),
        ('val4', _("val4 text")),

I am looking for function that returns list of all choices like: list=['val1', 'val2', 'val3', 'val4']

I could not manage to do it so far Is there any proper wat to get list of choices?

You can get the options data with:

>>> Your_Model.options.field.choices
(('var1', 'val1 text'), ('val2', 'val2 text'))

So, from that you can get a list of keys with:

>>> [c[0] for c in Your_Model.options.field.choices]
['var1', 'val2']

and use c[1] if you want the val text part.

Back to Top