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.py35
1 files changed, 34 insertions, 1 deletions
diff --git a/archaeological_warehouse/models.py b/archaeological_warehouse/models.py
index f6296f5e1..993ab3362 100644
--- a/archaeological_warehouse/models.py
+++ b/archaeological_warehouse/models.py
@@ -1875,7 +1875,12 @@ class Container(
("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")),
+ ("contained_documents_ref",
+ _("List of documents whose reference container is this container")),
+ ("find_denominations",
+ _("Deduplicated and sorted list of denominations inside the container")),
+ ("find_range_labels",
+ _("Get labels of first and last find of the container - list with first and last label")),
]
def get_material_types_code(self) -> str:
@@ -1900,6 +1905,30 @@ class Container(
materials.add(material)
return ", ".join(sorted(materials))
+ def get_find_range_labels(self) -> list:
+ """
+ Get labels of first and last find of the container
+ """
+ q = self.finds
+ if not q.count():
+ return ["", ""]
+ # first and last are get by order of import so by id
+ return [
+ q.values_list("label", flat=True).order_by("id").all()[0],
+ q.values_list("label", flat=True).order_by("-id").all()[0],
+ ]
+
+ def get_find_denominations(self) -> list:
+ """
+ List of denominations in the container
+ """
+ lst = []
+ for d in self.finds.values_list("denomination", flat=True).order_by(
+ "denomination").all():
+ if d not in lst:
+ lst.append(d)
+ return lst
+
def get_extra_values(self, prefix="", no_values=False, filtr=None, **kwargs):
values = {}
from_find = prefix.startswith("container_") or prefix.startswith(
@@ -1973,6 +2002,10 @@ class Container(
prefix=prefix, no_values=True, filtr=new_filtr, **kwargs
).items():
values[prefix + "operation_" + k] = v
+ if not filtr or prefix + "find_range_labels" in filtr:
+ values[prefix + "find_range_labels"] = self.get_find_range_labels()
+ if not filtr or prefix + "find_denominations" in filtr:
+ values[prefix + "find_denominations"] = self.get_find_denominations()
return values
def get_extra_actions(self, request):