MCPcopy
hub / github.com/django/django / valid_value

Method valid_value

django/forms/fields.py:903–915  ·  view source on GitHub ↗

Check to see if the provided value is a valid choice.

(self, value)

Source from the content-addressed store, hash-verified

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
918class TypedChoiceField(ChoiceField):

Callers 2

validateMethod · 0.95
validateMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected