Merge branch 'master' of github.com:tomchristie/django-rest-framework

This commit is contained in:
Tom Christie 2015-08-07 14:47:09 +01:00
commit fbd05aba57
2 changed files with 9 additions and 1 deletions

View File

@ -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)

View File

@ -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):