From 2168d3d915c21f1104244f77f88cc3474920d41c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ernesto=20P=C3=A9rez=20Amigo?= Date: Mon, 7 Jan 2019 22:00:20 +0100 Subject: [PATCH] Fixed minor bug with the type resolver of the ManyToMany fields on Django models. --- graphene_django_extras/__init__.py | 2 +- graphene_django_extras/utils.py | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/graphene_django_extras/__init__.py b/graphene_django_extras/__init__.py index c65a6a5..3c0a56a 100644 --- a/graphene_django_extras/__init__.py +++ b/graphene_django_extras/__init__.py @@ -9,7 +9,7 @@ from .paginations import LimitOffsetGraphqlPagination, PageGraphqlPagination, CursorGraphqlPagination from .types import DjangoObjectType, DjangoInputObjectType, DjangoListObjectType, DjangoSerializerType -VERSION = (0, 4, 2, 'final', '') +VERSION = (0, 4, 3, 'final', '') __version__ = get_version(VERSION) diff --git a/graphene_django_extras/utils.py b/graphene_django_extras/utils.py index 9c2efa0..ac94a02 100644 --- a/graphene_django_extras/utils.py +++ b/graphene_django_extras/utils.py @@ -17,10 +17,15 @@ def get_reverse_fields(model): - for name, attr in model.__dict__.items(): + reverse_fields = { + f.name: f for f in model._meta.get_fields() + if f.auto_created and not f.concrete + } + + for name, field in reverse_fields.items(): # Django =>1.9 uses 'rel', django <1.9 uses 'related' - related = getattr(attr, 'rel', None) or \ - getattr(attr, 'related', None) + related = getattr(field, 'rel', None) or \ + getattr(field, 'related', None) if isinstance(related, ManyToOneRel): yield (name, related) elif isinstance(related, ManyToManyRel) and not related.symmetrical: @@ -93,7 +98,7 @@ def get_model_fields(model): def get_obj(app_label, model_name, object_id): """ - Function used by my to get objst + Function used to get a object :param app_label: A valid Django Model or a string with format: . :param model_name: Key into kwargs that contains de data: new_person :param object_id: