From edfbbf52ef5745c409def954af6b520ac6a73506 Mon Sep 17 00:00:00 2001 From: Syrus Akbary Date: Tue, 31 May 2016 20:00:31 -0700 Subject: [PATCH] Fix field model --- graphene/contrib/django/converter.py | 5 +++-- graphene/contrib/django/tests/test_converter.py | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/graphene/contrib/django/converter.py b/graphene/contrib/django/converter.py index 951af2ad..24f035eb 100644 --- a/graphene/contrib/django/converter.py +++ b/graphene/contrib/django/converter.py @@ -20,8 +20,9 @@ def convert_choices(choices): def convert_django_field_with_choices(field): choices = getattr(field, 'choices', None) - if choices: - meta = field.model._meta + model = getattr(field, 'model', None) + if choices and model: + meta = model._meta name = '{}_{}_{}'.format(meta.app_label, meta.object_name, field.name) return Enum(name.upper(), list(convert_choices(choices)), description=field.help_text) return convert_django_field(field) diff --git a/graphene/contrib/django/tests/test_converter.py b/graphene/contrib/django/tests/test_converter.py index 32855599..978bf32d 100644 --- a/graphene/contrib/django/tests/test_converter.py +++ b/graphene/contrib/django/tests/test_converter.py @@ -124,7 +124,7 @@ def test_field_with_choices_gettext(): ('en', _('English')) )) - class TranslatedModel(models.Model): + class TranslatedChoicesModel(models.Model): language = field class Meta: