mirror of
https://github.com/graphql-python/graphene-django.git
synced 2024-11-22 17:47:12 +03:00
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
This commit is contained in:
commit
1bf5d602ce
|
@ -98,6 +98,9 @@ class DjangoObjectTypeMeta(ObjectTypeMeta):
|
|||
|
||||
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):
|
||||
|
@ -112,6 +115,6 @@ class DjangoObjectType(six.with_metaclass(DjangoObjectTypeMeta, ObjectType)):
|
|||
@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
|
||||
|
|
Loading…
Reference in New Issue
Block a user