diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2025-10-10 17:38:27 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2025-10-10 18:16:10 +0200 |
commit | 3a1c53b2d0605c56b96f398aba6847ded5398a4c (patch) | |
tree | 1d917b2dc66d8407195899601d9c4691b016776f | |
parent | 2319912a3ee1fd646063f70c4a499d526e34137c (diff) | |
download | Ishtar-3a1c53b2d0605c56b96f398aba6847ded5398a4c.tar.bz2 Ishtar-3a1c53b2d0605c56b96f398aba6847ded5398a4c.zip |
✨ container templates: find_denominations and find_range_labels
-rw-r--r-- | archaeological_warehouse/models.py | 35 |
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): |