Karan Kapadni
Karan Kapadni

Reputation: 45

How to get the form choice field values?

[enter image description hereForm._bound_fields_cache['limit'].field.choices[var][1]

I want to get the [][1] this value from each choice field how to get it.

I tried as above

where choice is need to be iterated but i am not getting it.

and need to append values in dictionary to it.

Thank you!

Upvotes: 0

Views: 443

Answers (1)

Matt
Matt

Reputation: 334

You can use list comprehension if you need a list. something like this:

[choice[1] for choice in Form._bound_fields_cache['limit'].field.choices]

or a more readable for loop:

choice_values = list()
for choice in Form._bound_fields_cache['limit'].field.choices:
    choice_values.append(choice[1])

Upvotes: 1

Related Questions