Skip to content

Commit 1bf5d60

Browse files
authored
Merge pull request #20 from morgante/pk_id
Fix ID lookup to handle cases where 'id' is not the primary key of the Django model
2 parents 31a4984 + 9003548 commit 1bf5d60

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

graphene_django/types.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ def __new__(cls, name, bases, attrs):
9898

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

101+
def resolve_id(self, args, context, info):
102+
return self.pk
103+
101104
@classmethod
102105
def is_type_of(cls, root, context, info):
103106
if isinstance(root, cls):
@@ -112,6 +115,6 @@ def is_type_of(cls, root, context, info):
112115
@classmethod
113116
def get_node(cls, id, context, info):
114117
try:
115-
return cls._meta.model.objects.get(id=id)
118+
return cls._meta.model.objects.get(pk=id)
116119
except cls._meta.model.DoesNotExist:
117120
return None

0 commit comments

Comments
 (0)