mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-01-23 15:54:16 +03:00
Merge pull request #3238 from kezabelle/bugfix/3235
Fixed #3235 - ListField now returns the QueryDict value even if it's a list of only one item.
This commit is contained in:
commit
368fb9fb2a
|
@ -1391,7 +1391,7 @@ class ListField(Field):
|
||||||
# lists in HTML forms.
|
# lists in HTML forms.
|
||||||
if html.is_html_input(dictionary):
|
if html.is_html_input(dictionary):
|
||||||
val = dictionary.getlist(self.field_name, [])
|
val = dictionary.getlist(self.field_name, [])
|
||||||
if len(val) > 1:
|
if len(val) > 0:
|
||||||
# Support QueryDict lists in HTML input.
|
# Support QueryDict lists in HTML input.
|
||||||
return val
|
return val
|
||||||
return html.parse_html_list(dictionary, prefix=self.field_name)
|
return html.parse_html_list(dictionary, prefix=self.field_name)
|
||||||
|
|
|
@ -317,6 +317,14 @@ class TestHTMLInput:
|
||||||
assert serializer.is_valid()
|
assert serializer.is_valid()
|
||||||
assert serializer.validated_data == {'scores': [1, 3]}
|
assert serializer.validated_data == {'scores': [1, 3]}
|
||||||
|
|
||||||
|
def test_querydict_list_input_only_one_input(self):
|
||||||
|
class TestSerializer(serializers.Serializer):
|
||||||
|
scores = serializers.ListField(child=serializers.IntegerField())
|
||||||
|
|
||||||
|
serializer = TestSerializer(data=QueryDict('scores=1&'))
|
||||||
|
assert serializer.is_valid()
|
||||||
|
assert serializer.validated_data == {'scores': [1]}
|
||||||
|
|
||||||
|
|
||||||
class TestCreateOnlyDefault:
|
class TestCreateOnlyDefault:
|
||||||
def setup(self):
|
def setup(self):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user