diff --git a/graphene/contrib/django/types.py b/graphene/contrib/django/types.py index 8e6a3f57..56f0237b 100644 --- a/graphene/contrib/django/types.py +++ b/graphene/contrib/django/types.py @@ -26,7 +26,11 @@ class DjangoObjectTypeMeta(ObjectTypeMeta): return only_fields = cls._meta.only_fields reverse_fields = tuple(get_reverse_fields(cls._meta.model)) - for field in cls._meta.model._meta.fields + reverse_fields: + all_fields = (list(cls._meta.model._meta.local_fields) + + list(reverse_fields) + + list(cls._meta.model._meta.local_many_to_many)) + + for field in all_fields: is_not_in_only = only_fields and field.name not in only_fields is_excluded = field.name in cls._meta.exclude_fields if is_not_in_only or is_excluded: diff --git a/tests/contrib_django/models.py b/tests/contrib_django/models.py index 7ded5f4f..72ed0821 100644 --- a/tests/contrib_django/models.py +++ b/tests/contrib_django/models.py @@ -2,10 +2,15 @@ from __future__ import absolute_import from django.db import models +class Pet(models.Model): + name = models.CharField(max_length=30) + + class Reporter(models.Model): first_name = models.CharField(max_length=30) last_name = models.CharField(max_length=30) email = models.EmailField() + pets = models.ManyToManyField('self') def __str__(self): # __unicode__ on Python 2 return "%s %s" % (self.first_name, self.last_name) diff --git a/tests/contrib_django/test_converter.py b/tests/contrib_django/test_converter.py index 7e587fa9..9d1439c0 100644 --- a/tests/contrib_django/test_converter.py +++ b/tests/contrib_django/test_converter.py @@ -89,9 +89,10 @@ def test_should_float_convert_float(): def test_should_manytomany_convert_connectionorlist(): - field = assert_conversion(models.ManyToManyField, ConnectionOrListField, Article) - assert isinstance(field.field_type, DjangoModelField) - assert field.field_type.model == Article + graphene_type = convert_django_field(Reporter._meta.local_many_to_many[0]) + assert isinstance(graphene_type, ConnectionOrListField) + assert isinstance(graphene_type.field_type, DjangoModelField) + assert graphene_type.field_type.model == Reporter def test_should_manytoone_convert_connectionorlist(): diff --git a/tests/contrib_django/test_schema.py b/tests/contrib_django/test_schema.py index 6469913b..95003004 100644 --- a/tests/contrib_django/test_schema.py +++ b/tests/contrib_django/test_schema.py @@ -50,7 +50,7 @@ def test_should_map_fields_correctly(): class Meta: model = Reporter assert ReporterType2._meta.fields_map.keys( - ) == ['articles', 'first_name', 'last_name', 'id', 'email'] + ) == ['articles', 'first_name', 'last_name', 'email', 'pets', 'id'] def test_should_map_fields(): diff --git a/tests/contrib_django/test_types.py b/tests/contrib_django/test_types.py index 1ab8bd47..28435a13 100644 --- a/tests/contrib_django/test_types.py +++ b/tests/contrib_django/test_types.py @@ -49,7 +49,7 @@ def test_pseudo_interface(): assert isinstance(object_type, GraphQLInterfaceType) assert Character._meta.model == Reporter assert object_type.get_fields().keys() == [ - 'lastName', 'email', 'id', 'firstName', 'articles'] + 'articles', 'firstName', 'lastName', 'email', 'pets', 'id'] def test_interface_resolve_type():