Skip to content

Fix ID lookup to handle cases where 'id' is not the primary key of the Django model #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 15, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion graphene_django/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ def __new__(cls, name, bases, attrs):

class DjangoObjectType(six.with_metaclass(DjangoObjectTypeMeta, ObjectType)):

def resolve_id(self, args, context, info):
return self.pk

@classmethod
def is_type_of(cls, root, context, info):
if isinstance(root, cls):
Expand All @@ -112,6 +115,6 @@ def is_type_of(cls, root, context, info):
@classmethod
def get_node(cls, id, context, info):
try:
return cls._meta.model.objects.get(id=id)
return cls._meta.model.objects.get(pk=id)
except cls._meta.model.DoesNotExist:
return None