fixed field choices realisation

This commit is contained in:
Mardanov Timur Rustemovich 2018-11-20 12:09:28 +03:00
parent 1ecc760a6b
commit 890ef28b85

View File

@ -107,8 +107,8 @@ def convert_django_field_with_choices(field, registry=None):
return converted return converted
choices = getattr(field, "choices", None) choices = getattr(field, "choices", None)
if choices: if choices:
meta = field.model._meta field_class = field.owner
name = to_camel_case("{}_{}".format(meta.object_name, field.name)) name = to_camel_case("{}_{}".format(field_class.__name__, field.name))
choices = list(get_choices(choices)) choices = list(get_choices(choices))
named_choices = [(c[0], c[1]) for c in choices] named_choices = [(c[0], c[1]) for c in choices]
named_choices_descriptions = {c[0]: c[2] for c in choices} named_choices_descriptions = {c[0]: c[2] for c in choices}
@ -119,7 +119,7 @@ def convert_django_field_with_choices(field, registry=None):
return named_choices_descriptions[self.name] return named_choices_descriptions[self.name]
enum = Enum(name, list(named_choices), type=EnumWithDescriptionsType) enum = Enum(name, list(named_choices), type=EnumWithDescriptionsType)
converted = enum(description=field.help_text, required=not field.null) converted = enum(description=field.help_text, required=field.required)
else: else:
converted = convert_django_field(field, registry) converted = convert_django_field(field, registry)
if registry is not None: if registry is not None: