summaryrefslogtreecommitdiff
path: root/archaeological_warehouse/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'archaeological_warehouse/models.py')
-rw-r--r--archaeological_warehouse/models.py41
1 files changed, 30 insertions, 11 deletions
diff --git a/archaeological_warehouse/models.py b/archaeological_warehouse/models.py
index 5df824d8f..5e1477129 100644
--- a/archaeological_warehouse/models.py
+++ b/archaeological_warehouse/models.py
@@ -25,7 +25,7 @@ import uuid
from django.contrib.gis.db import models
from django.contrib.postgres.indexes import GinIndex
from django.core.exceptions import ObjectDoesNotExist
-from django.db.models import Q, Max, Count
+from django.db.models import Q, Max
from django.db.models.signals import post_save, post_delete, m2m_changed, pre_delete
from django.template.defaultfilters import slugify
from django.urls import reverse
@@ -33,7 +33,7 @@ from ishtar_common.utils import ugettext_lazy as _, pgettext_lazy
from django.apps import apps
from ishtar_common.data_importer import post_importer_action, pre_importer_action, ImporterError
-from ishtar_common.model_managers import ExternalIdManager, UUIDModelManager
+from ishtar_common.model_managers import UUIDModelManager
from ishtar_common.models import ValueGetter, get_current_profile, HistoryModel, Imported
from ishtar_common.models_common import (
GeneralType,
@@ -45,7 +45,6 @@ from ishtar_common.models_common import (
DashboardFormItem,
document_attached_changed,
SearchAltName,
- DynamicRequest,
GeoItem,
CompleteIdentifierItem,
SearchVectorConfig,
@@ -1508,16 +1507,26 @@ class Container(
def get_town_polygons(self):
return self.location.get_town_polygons()
+ @property
def contained_documents(self):
- if not self.pk:
- return
+ """
+ Documents contained in this container.
+ A Document queryset is returned
+ """
Document = apps.get_model("ishtar_common", "Document")
+ if not self.pk:
+ return Document.objects.filter(pk__isnull=True)
return Document.objects.filter(container_id=self.pk)
+ @property
def contained_documents_ref(self):
- if not self.pk:
- return
+ """
+ Documents whose reference container is this container.
+ A Document queryset is returned
+ """
Document = apps.get_model("ishtar_common", "Document")
+ if not self.pk:
+ return Document.objects.filter(pk__isnull=True)
return Document.objects.filter(container_ref_id=self.pk)
@property
@@ -1811,6 +1820,8 @@ class Container(
("material_types", _("Material types inside the container - string")),
("material_types_code", _("Material types code - string")),
("finds", _("List of associated finds")),
+ ("contained_documents", _("List of documents contained in this container")),
+ ("contained_documents_ref", _("List of documents whose reference container is this container")),
]
def get_material_types_code(self) -> str:
@@ -1835,10 +1846,8 @@ class Container(
materials.add(material)
return ", ".join(sorted(materials))
- def get_values(self, prefix="", no_values=False, filtr=None, **kwargs):
- values = super(Container, self).get_values(
- prefix=prefix, no_values=no_values, filtr=filtr, **kwargs
- )
+ def get_extra_values(self, prefix="", no_values=False, filtr=None, **kwargs):
+ values = {}
from_find = prefix.startswith("container_") or prefix.startswith(
"container_ref_"
)
@@ -1855,6 +1864,16 @@ class Container(
f.get_values(prefix=prefix, no_values=True, filtr=filtr, **kwargs)
for f in self.finds.distinct().order_by("index").all()
]
+ if not filtr or prefix + "contained_documents" in filtr:
+ values[prefix + "contained_documents"] = [
+ doc.get_values(prefix=prefix, no_values=True, filtr=filtr, **kwargs)
+ for doc in self.contained_documents.distinct().order_by("index").all()
+ ]
+ if not filtr or prefix + "contained_documents_ref" in filtr:
+ values[prefix + "contained_documents_ref"] = [
+ doc.get_values(prefix=prefix, no_values=True, filtr=filtr, **kwargs)
+ for doc in self.contained_documents_ref.distinct().order_by("index").all()
+ ]
if not self.finds.count():
return values