Skip to content

Commit 4c0c821

Browse files
authored
Register MultipleChoiceField as list type (#1033)
In general I welcome reviews even from non-maintainers to build confidence. I haven't seen any objections and this has sat with approval for a week so I am going to go ahead and merge.
1 parent 4b7119d commit 4c0c821

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

graphene_django/forms/converter.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ def convert_form_field_to_list(field):
6363
return List(ID, required=field.required)
6464

6565

66+
@convert_form_field.register(forms.MultipleChoiceField)
67+
def convert_form_field_to_string_list(field):
68+
return List(String, required=field.required)
69+
70+
6671
@convert_form_field.register(forms.DateField)
6772
def convert_form_field_to_date(field):
6873
return Date(description=field.help_text, required=field.required)

graphene_django/forms/tests/test_converter.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,14 @@ def test_should_decimal_convert_float():
101101
assert_conversion(forms.DecimalField, Float)
102102

103103

104-
def test_should_multiple_choice_convert_connectionorlist():
104+
def test_should_multiple_choice_convert_list():
105+
field = forms.MultipleChoiceField()
106+
graphene_type = convert_form_field(field)
107+
assert isinstance(graphene_type, List)
108+
assert graphene_type.of_type == String
109+
110+
111+
def test_should_model_multiple_choice_convert_connectionorlist():
105112
field = forms.ModelMultipleChoiceField(queryset=None)
106113
graphene_type = convert_form_field(field)
107114
assert isinstance(graphene_type, List)

0 commit comments

Comments
 (0)