mirror of
https://github.com/graphql-python/graphene.git
synced 2024-11-11 12:16:58 +03:00
Fixed Django converter of field with grouped choices
This commit is contained in:
parent
4636f9290a
commit
9e715cd902
|
@ -15,16 +15,20 @@ singledispatch = import_single_dispatch()
|
||||||
|
|
||||||
def convert_choices(choices):
|
def convert_choices(choices):
|
||||||
for value, name in choices:
|
for value, name in choices:
|
||||||
yield to_const(force_text(name)), value
|
if isinstance(name, (tuple, list)):
|
||||||
|
for choice in convert_choices(name):
|
||||||
|
yield choice
|
||||||
|
else:
|
||||||
|
yield to_const(force_text(name)), value
|
||||||
|
|
||||||
|
|
||||||
def convert_django_field_with_choices(field):
|
def convert_django_field_with_choices(field):
|
||||||
choices = getattr(field, 'choices', None)
|
choices = getattr(field, 'choices', None)
|
||||||
model = getattr(field, 'model', None)
|
if choices:
|
||||||
if choices and model:
|
meta = field.model._meta
|
||||||
meta = model._meta
|
|
||||||
name = '{}_{}_{}'.format(meta.app_label, meta.object_name, field.name)
|
name = '{}_{}_{}'.format(meta.app_label, meta.object_name, field.name)
|
||||||
return Enum(name.upper(), list(convert_choices(choices)), description=field.help_text)
|
graphql_choices = list(convert_choices(choices))
|
||||||
|
return Enum(name.upper(), graphql_choices, description=field.help_text)
|
||||||
return convert_django_field(field)
|
return convert_django_field(field)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user