summaryrefslogtreecommitdiff
path: root/archaeological_finds/models_finds.py
diff options
context:
space:
mode:
Diffstat (limited to 'archaeological_finds/models_finds.py')
-rw-r--r--archaeological_finds/models_finds.py44
1 files changed, 36 insertions, 8 deletions
diff --git a/archaeological_finds/models_finds.py b/archaeological_finds/models_finds.py
index 432bd5467..3b6392039 100644
--- a/archaeological_finds/models_finds.py
+++ b/archaeological_finds/models_finds.py
@@ -71,17 +71,18 @@ from ishtar_common.models import (
SearchVectorConfig,
ValueGetter,
)
-from ishtar_common.models_common import HistoricalRecords, Imported, SerializeItem, \
+from ishtar_common.models_common import HistoricalRecords, SerializeItem, \
GeoVectorData, geodata_attached_changed
from ishtar_common.utils import PRIVATE_FIELDS
from archaeological_operations.models import (
AdministrativeAct,
- Operation,
CulturalAttributionType,
+ Operation,
+ Period,
)
-from archaeological_context_records.models import ContextRecord, Dating, \
+from archaeological_context_records.models import BaseDating, ContextRecord, Dating, \
GeographicSubTownItem
from archaeological_warehouse.models import Warehouse
@@ -1285,6 +1286,7 @@ class Find(
"container__cached_label": _("Current container"),
"container_ref__cached_label": _("Reference container"),
"datings__period__label": _("Periods"),
+ "periods__label": _("Periods"),
"cached_periods": _("Periods"),
"material_types__label": _("Material types"),
"cached_materials": _("Material types"),
@@ -1322,7 +1324,7 @@ class Find(
"base_finds__context_record__operation__towns__areas__parent__label",
_("Extended area"),
),
- ("datings__period__label", _("Chronological period")),
+ ("periods__label", _("Chronological period")),
("material_types__label", _("Material type")),
("object_types__label", _("Object type")),
("recommended_treatments__label", _("Recommended treatments")),
@@ -1513,6 +1515,11 @@ class Find(
pgettext_lazy("key for text search", "object-type"),
"object_types__label__iexact",
),
+ "periods": SearchAltName(
+ pgettext_lazy("key for text search", "period"),
+ "periods__label__iexact",
+ related_name="periods",
+ ),
"recommended_treatments": SearchAltName(
pgettext_lazy("key for text search", "recommended-treatments"),
"recommended_treatments__label__iexact",
@@ -1958,7 +1965,7 @@ class Find(
SearchVectorConfig("museum_inventory_transcript", "local"),
]
M2M_SEARCH_VECTORS = [
- SearchVectorConfig("datings__period__label", "local"),
+ SearchVectorConfig("periods__label", "local"),
SearchVectorConfig("integrities__label", "raw"),
SearchVectorConfig("material_types__label", "local"),
SearchVectorConfig("object_types__label", "raw"),
@@ -2064,7 +2071,7 @@ class Find(
HISTORICAL_M2M = [
"material_types",
"technical_processes",
- "datings",
+ # "datings",
"cultural_attributions",
"conservatory_states",
"object_types",
@@ -2207,9 +2214,10 @@ class Find(
verbose_name=_("Downstream treatment"),
on_delete=models.SET_NULL,
)
- datings = models.ManyToManyField(
+ datings_old = models.ManyToManyField(
Dating, verbose_name=_("Dating"), related_name="find"
)
+ periods = models.ManyToManyField(Period, verbose_name=_("Periods"), blank=True)
cultural_attributions = models.ManyToManyField(
CulturalAttributionType, verbose_name=_("Cultural attribution"), blank=True
)
@@ -2937,6 +2945,10 @@ class Find(
return self.documents.count()
@property
+ def periods_count(self):
+ return self.periods.count()
+
+ @property
def operation(self):
bf = self.get_first_base_find()
if not bf or not bf.context_record or not bf.context_record.operation:
@@ -3246,7 +3258,7 @@ class Find(
return get_generated_id("museum_complete_identifier", self) or ""
def _generate_cached_periods(self):
- return " & ".join([dating.period.label for dating in self.datings.all()])
+ return " & ".join([period.label for period in self.periods.all()])
def _generate_cached_object_types(self):
return " & ".join([str(obj) for obj in self.object_types.all()])
@@ -3820,6 +3832,22 @@ m2m_changed.connect(base_find_find_changed, sender=Find.base_finds.through)
m2m_changed.connect(document_attached_changed, sender=Find.documents.through)
+class FindDating(BaseDating):
+ SERIALIZE_EXCLUDE = ["find"]
+ CURRENT_MODEL = Find
+
+ find = models.ForeignKey(
+ Find,
+ verbose_name=_("Find"),
+ related_name="datings",
+ on_delete=models.CASCADE,
+ )
+
+ class Meta:
+ verbose_name = _("Find dating")
+ verbose_name_plural = _("Find datings")
+
+
class FindInsideContainer(models.Model):
CREATE_SQL = """
CREATE VIEW find_inside_container AS