Check to see if the provided value is a valid choice.
(self, value)
| 901 | ) |
| 902 | |
| 903 | def valid_value(self, value): |
| 904 | """Check to see if the provided value is a valid choice.""" |
| 905 | text_value = str(value) |
| 906 | for k, v in self.choices: |
| 907 | if isinstance(v, (list, tuple)): |
| 908 | # This is an optgroup, so look inside the group for options |
| 909 | for k2, v2 in v: |
| 910 | if value == k2 or text_value == str(k2): |
| 911 | return True |
| 912 | else: |
| 913 | if value == k or text_value == str(k): |
| 914 | return True |
| 915 | return False |
| 916 | |
| 917 | |
| 918 | class TypedChoiceField(ChoiceField): |