mirror of
https://github.com/graphql-python/graphene-django.git
synced 2024-11-29 13:03:44 +03:00
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:
commit
bb0b4fa766
|
@ -38,6 +38,7 @@ class Article(models.Model):
|
||||||
headline = models.CharField(max_length=100)
|
headline = models.CharField(max_length=100)
|
||||||
pub_date = models.DateField()
|
pub_date = models.DateField()
|
||||||
reporter = models.ForeignKey(Reporter, related_name='articles')
|
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=[
|
lang = models.CharField(max_length=2, help_text='Language', choices=[
|
||||||
('es', 'Spanish'),
|
('es', 'Spanish'),
|
||||||
('en', 'English')
|
('en', 'English')
|
||||||
|
|
|
@ -52,7 +52,7 @@ def test_django_objecttype_map_correct_fields():
|
||||||
|
|
||||||
def test_django_objecttype_with_node_have_correct_fields():
|
def test_django_objecttype_with_node_have_correct_fields():
|
||||||
fields = Article._meta.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():
|
def test_schema_representation():
|
||||||
|
@ -66,6 +66,7 @@ type Article implements Node {
|
||||||
headline: String!
|
headline: String!
|
||||||
pubDate: DateTime!
|
pubDate: DateTime!
|
||||||
reporter: Reporter!
|
reporter: Reporter!
|
||||||
|
editor: Reporter!
|
||||||
lang: ArticleLang!
|
lang: ArticleLang!
|
||||||
importance: ArticleImportance
|
importance: ArticleImportance
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,9 +26,12 @@ def construct_fields(options):
|
||||||
is_not_in_only = only_fields and name not in options.only_fields
|
is_not_in_only = only_fields and name not in options.only_fields
|
||||||
is_already_created = name in options.fields
|
is_already_created = name in options.fields
|
||||||
is_excluded = name in exclude_fields or is_already_created
|
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
|
# 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
|
continue
|
||||||
converted = convert_django_field_with_choices(field, options.registry)
|
converted = convert_django_field_with_choices(field, options.registry)
|
||||||
if not converted:
|
if not converted:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user