Skip to content

Commit 9e715cd

Browse files
committed
Fixed Django converter of field with grouped choices
1 parent 4636f92 commit 9e715cd

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

graphene/contrib/django/converter.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,20 @@
1515

1616
def convert_choices(choices):
1717
for value, name in choices:
18-
yield to_const(force_text(name)), value
18+
if isinstance(name, (tuple, list)):
19+
for choice in convert_choices(name):
20+
yield choice
21+
else:
22+
yield to_const(force_text(name)), value
1923

2024

2125
def convert_django_field_with_choices(field):
2226
choices = getattr(field, 'choices', None)
23-
model = getattr(field, 'model', None)
24-
if choices and model:
25-
meta = model._meta
27+
if choices:
28+
meta = field.model._meta
2629
name = '{}_{}_{}'.format(meta.app_label, meta.object_name, field.name)
27-
return Enum(name.upper(), list(convert_choices(choices)), description=field.help_text)
30+
graphql_choices = list(convert_choices(choices))
31+
return Enum(name.upper(), graphql_choices, description=field.help_text)
2832
return convert_django_field(field)
2933

3034

0 commit comments

Comments
 (0)