Merge pull request #47 from timothyjlaurent/#46-Dont-follow-related-name-with-plus

solves #46 don\'t use fields that end in a plus
This commit is contained in:
Syrus Akbary 2016-11-10 10:34:05 -08:00 committed by GitHub
commit bb0b4fa766
3 changed files with 8 additions and 3 deletions

View File

@ -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')

View File

@ -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
}

View File

@ -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: