summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--archaeological_context_records/models.py5
-rw-r--r--archaeological_operations/models.py40
2 files changed, 36 insertions, 9 deletions
diff --git a/archaeological_context_records/models.py b/archaeological_context_records/models.py
index 800a6604b..2eb9c0380 100644
--- a/archaeological_context_records/models.py
+++ b/archaeological_context_records/models.py
@@ -30,8 +30,7 @@ from django.db.models import Q
from django.db.models.signals import m2m_changed, pre_delete, post_delete, post_save
from django.urls import reverse, reverse_lazy
-from ishtar_common.utils import get_generated_id, gettext_lazy as _, pgettext_lazy, \
- pgettext
+from ishtar_common.utils import gettext_lazy as _, pgettext_lazy, pgettext
from django.utils.text import slugify
@@ -395,7 +394,7 @@ class ContextRecord(
[
("unit__label", _("Context record type")),
("operation__cached_label", _("Operation")),
- ("datings__period__label", _("Chronological period")),
+ ("periods__label", _("Chronological period")),
("identifications__label", _("Identification")),
("activity__label", _("Activity")),
("excavation_technics__label", _("Excavation techniques")),
diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py
index 9d9e227b0..c6706c7dc 100644
--- a/archaeological_operations/models.py
+++ b/archaeological_operations/models.py
@@ -36,11 +36,15 @@ from django.db.models.signals import m2m_changed, post_save, post_delete, pre_de
from django.forms import ValidationError
from django.urls import reverse, reverse_lazy
from ishtar_common.data_importer import post_importer_action
-from ishtar_common.utils import gettext_lazy as _, pgettext_lazy, get_generated_id
+from ishtar_common.utils import (
+ gettext_lazy as _, pgettext_lazy, get_generated_id,
+ related_historization_changed
+)
from ishtar_common.models import (
Area,
Author,
+ BaseDating,
BaseHistorizedItem,
DashboardFormItem,
Document,
@@ -613,8 +617,10 @@ class ArchaeologicalSite(
RELATIVE_SESSION_NAMES = [
("operation", "operations__pk"),
]
- HISTORICAL_M2M = ["periods", "remains", "towns", "cultural_attributions", "types",
- "heritage_interests", "heritage_environmental_protections"]
+ HISTORICAL_M2M = [
+ "datings", "periods", "remains", "towns", "cultural_attributions", "types",
+ "heritage_interests", "heritage_environmental_protections"
+ ]
CACHED_LABELS = [
"cached_label",
"cached_towns_label",
@@ -1149,11 +1155,33 @@ m2m_changed.connect(geodata_attached_changed, sender=ArchaeologicalSite.geodata.
m2m_changed.connect(geotown_attached_changed, sender=ArchaeologicalSite.towns.through)
-for attr in ArchaeologicalSite.HISTORICAL_M2M:
- m2m_changed.connect(
- m2m_historization_changed, sender=getattr(ArchaeologicalSite, attr).through
+class SiteDating(BaseDating):
+ SERIALIZE_EXCLUDE = ["site"]
+ CURRENT_MODEL = ArchaeologicalSite
+ CURRENT_MODEL_ATTR = "site"
+
+ site = models.ForeignKey(
+ ArchaeologicalSite,
+ verbose_name=_("Site"),
+ related_name="datings",
+ on_delete=models.CASCADE,
)
+ class Meta:
+ verbose_name = _("Site dating")
+ verbose_name_plural = _("Site datings")
+
+
+for attr in ArchaeologicalSite.HISTORICAL_M2M:
+ if attr == "datings":
+ model = SiteDating
+ post_save.connect(related_historization_changed, sender=SiteDating)
+ post_delete.connect(related_historization_changed, sender=SiteDating)
+ else:
+ m2m_changed.connect(
+ m2m_historization_changed, sender=getattr(ArchaeologicalSite, attr).through
+ )
+
def get_values_town_related(item, prefix, values, filtr=None):
if not filtr or prefix + "parcellist" in filtr: