We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 75beb6a commit c5a04a8Copy full SHA for c5a04a8
tests/test_fields.py
@@ -1070,6 +1070,22 @@ def test_allow_blank(self):
1070
output = field.run_validation('')
1071
assert output == ''
1072
1073
+ def test_allow_null(self):
1074
+ """
1075
+ If `allow_null=True` then '' on HTML forms is treated as None.
1076
1077
+ field = serializers.ChoiceField(
1078
+ allow_null=True,
1079
+ choices=[
1080
+ 1, 2, 3
1081
+ ]
1082
+ )
1083
+ field.field_name = 'example'
1084
+ value = field.get_value(QueryDict('example='))
1085
+ assert value is None
1086
+ output = field.run_validation(None)
1087
+ assert output is None
1088
+
1089
1090
class TestChoiceFieldWithType(FieldValues):
1091
"""
0 commit comments