Skip to content

Commit bb0b4fa

Browse files
authored
Merge pull request #47 from timothyjlaurent/#46-Dont-follow-related-name-with-plus
solves #46 don\'t use fields that end in a plus
2 parents d524718 + 1fdd775 commit bb0b4fa

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

graphene_django/tests/models.py

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class Article(models.Model):
3838
headline = models.CharField(max_length=100)
3939
pub_date = models.DateField()
4040
reporter = models.ForeignKey(Reporter, related_name='articles')
41+
editor = models.ForeignKey(Reporter, related_name='edited_articles_+')
4142
lang = models.CharField(max_length=2, help_text='Language', choices=[
4243
('es', 'Spanish'),
4344
('en', 'English')

graphene_django/tests/test_types.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def test_django_objecttype_map_correct_fields():
5252

5353
def test_django_objecttype_with_node_have_correct_fields():
5454
fields = Article._meta.fields
55-
assert list(fields.keys()) == ['id', 'headline', 'pub_date', 'reporter', 'lang', 'importance']
55+
assert list(fields.keys()) == ['id', 'headline', 'pub_date', 'reporter', 'editor', 'lang', 'importance']
5656

5757

5858
def test_schema_representation():
@@ -66,6 +66,7 @@ def test_schema_representation():
6666
headline: String!
6767
pubDate: DateTime!
6868
reporter: Reporter!
69+
editor: Reporter!
6970
lang: ArticleLang!
7071
importance: ArticleImportance
7172
}

graphene_django/types.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,12 @@ def construct_fields(options):
2626
is_not_in_only = only_fields and name not in options.only_fields
2727
is_already_created = name in options.fields
2828
is_excluded = name in exclude_fields or is_already_created
29-
if is_not_in_only or is_excluded:
29+
# https://docs.djangoproject.com/en/1.10/ref/models/fields/#django.db.models.ForeignKey.related_query_name
30+
is_no_backref = str(name).endswith('+')
31+
if is_not_in_only or is_excluded or is_no_backref:
3032
# We skip this field if we specify only_fields and is not
31-
# in there. Or when we exclude this field in exclude_fields
33+
# in there. Or when we exclude this field in exclude_fields.
34+
# Or when there is no back reference.
3235
continue
3336
converted = convert_django_field_with_choices(field, options.registry)
3437
if not converted:

0 commit comments

Comments
 (0)