Skip to content

Commit

Permalink
Fixed minor bug with the type resolver of the ManyToMany fields on Dj…
Browse files Browse the repository at this point in the history
…ango models.
  • Loading branch information
eamigo86 committed Jan 7, 2019
1 parent b8a661a commit 2168d3d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion graphene_django_extras/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
13 changes: 9 additions & 4 deletions graphene_django_extras/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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: <app_label>.<model_name>
:param model_name: Key into kwargs that contains de data: new_person
:param object_id:
Expand Down

0 comments on commit 2168d3d

Please sign in to comment.