# Extends Id lookup
* extends ID lookup to support external ids as well as internal ids
This commit is contained in:
@@ -10,9 +10,11 @@ from abc import abstractmethod
|
|||||||
|
|
||||||
from django.contrib.gis import geos
|
from django.contrib.gis import geos
|
||||||
from django.contrib.gis.geos import GEOSGeometry
|
from django.contrib.gis.geos import GEOSGeometry
|
||||||
|
from django.core.exceptions import ObjectDoesNotExist
|
||||||
from django.core.paginator import Paginator
|
from django.core.paginator import Paginator
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
|
|
||||||
|
from api.models import ExternalIdentifier
|
||||||
from konova.models import Geometry
|
from konova.models import Geometry
|
||||||
from konova.utils.message_templates import DATA_UNSHARED
|
from konova.utils.message_templates import DATA_UNSHARED
|
||||||
|
|
||||||
@@ -76,6 +78,14 @@ class AbstractModelAPISerializer:
|
|||||||
del self.lookup["id"]
|
del self.lookup["id"]
|
||||||
else:
|
else:
|
||||||
# Return certain object
|
# Return certain object
|
||||||
|
## But first check, whether this is an external identifier ...
|
||||||
|
try:
|
||||||
|
## If we can find this _id on our ExternalIdentifier model, we need to map it on the internal id
|
||||||
|
ext_id = ExternalIdentifier.objects.get(external_id=_id)
|
||||||
|
_id = ext_id.internal_id
|
||||||
|
except ObjectDoesNotExist:
|
||||||
|
# If we did not find it, we assume that this is already an internal id. (Or it does not exist at all)
|
||||||
|
pass
|
||||||
self.lookup["id"] = _id
|
self.lookup["id"] = _id
|
||||||
|
|
||||||
self.shared_lookup = Q(
|
self.shared_lookup = Q(
|
||||||
|
|||||||
Reference in New Issue
Block a user