Skip to content

Commit

Permalink
Merge pull request #23 from morgante/fix_choice_enums
Browse files Browse the repository at this point in the history
Fix #19 by using choice keys as enum keys, not choice descriptions
  • Loading branch information
syrusakbary committed Oct 15, 2016
2 parents 1bf5d60 + 5ad21f1 commit 3a9ffba
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions graphene_django/converter.py
Expand Up @@ -7,6 +7,7 @@
from graphene.types.datetime import DateTime
from graphene.types.json import JSONString
from graphene.utils.str_converters import to_const
from graphql import assert_valid_name

from .compat import (ArrayField, HStoreField, JSONField, RangeField,
RelatedObject, UUIDField)
Expand All @@ -17,7 +18,12 @@


def convert_choice_name(name):
return to_const(force_text(name))
name = to_const(force_text(name))
try:
assert_valid_name(name)
except AssertionError:
name = "A_%s" % name
return name


def get_choices(choices):
Expand All @@ -26,7 +32,7 @@ def get_choices(choices):
for choice in get_choices(help_text):
yield choice
else:
name = convert_choice_name(help_text)
name = convert_choice_name(value)
description = help_text
yield name, value, description

Expand Down

0 comments on commit 3a9ffba

Please sign in to comment.