diff --git a/graphene_django/tests/models.py b/graphene_django/tests/models.py index a055912..0c62f28 100644 --- a/graphene_django/tests/models.py +++ b/graphene_django/tests/models.py @@ -38,6 +38,7 @@ class Article(models.Model): headline = models.CharField(max_length=100) pub_date = models.DateField() reporter = models.ForeignKey(Reporter, related_name='articles') + editor = models.ForeignKey(Reporter, related_name='edited_articles_+') lang = models.CharField(max_length=2, help_text='Language', choices=[ ('es', 'Spanish'), ('en', 'English') diff --git a/graphene_django/tests/test_types.py b/graphene_django/tests/test_types.py index 2510e1d..5c04651 100644 --- a/graphene_django/tests/test_types.py +++ b/graphene_django/tests/test_types.py @@ -52,7 +52,7 @@ def test_django_objecttype_map_correct_fields(): def test_django_objecttype_with_node_have_correct_fields(): fields = Article._meta.fields - assert list(fields.keys()) == ['id', 'headline', 'pub_date', 'reporter', 'lang', 'importance'] + assert list(fields.keys()) == ['id', 'headline', 'pub_date', 'reporter', 'editor', 'lang', 'importance'] def test_schema_representation(): @@ -66,6 +66,7 @@ type Article implements Node { headline: String! pubDate: DateTime! reporter: Reporter! + editor: Reporter! lang: ArticleLang! importance: ArticleImportance } diff --git a/graphene_django/types.py b/graphene_django/types.py index ae2dc18..1973a85 100644 --- a/graphene_django/types.py +++ b/graphene_django/types.py @@ -26,9 +26,12 @@ def construct_fields(options): is_not_in_only = only_fields and name not in options.only_fields is_already_created = name in options.fields is_excluded = name in exclude_fields or is_already_created - if is_not_in_only or is_excluded: + # https://docs.djangoproject.com/en/1.10/ref/models/fields/#django.db.models.ForeignKey.related_query_name + is_no_backref = str(name).endswith('+') + if is_not_in_only or is_excluded or is_no_backref: # We skip this field if we specify only_fields and is not - # in there. Or when we exclude this field in exclude_fields + # in there. Or when we exclude this field in exclude_fields. + # Or when there is no back reference. continue converted = convert_django_field_with_choices(field, options.registry) if not converted: