diff options
Diffstat (limited to 'archaeological_finds/models_finds.py')
| -rw-r--r-- | archaeological_finds/models_finds.py | 54 |
1 files changed, 46 insertions, 8 deletions
diff --git a/archaeological_finds/models_finds.py b/archaeological_finds/models_finds.py index 432bd5467..b79c21c69 100644 --- a/archaeological_finds/models_finds.py +++ b/archaeological_finds/models_finds.py @@ -34,6 +34,7 @@ from ishtar_common.data_importer import post_importer_action, ImporterError from ishtar_common.utils import ( cached_label_changed, get_generated_id, + related_historization_changed, m2m_historization_changed, pgettext_lazy, post_save_geo, @@ -71,17 +72,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 +1287,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 +1325,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 +1516,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 +1966,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,6 +2072,7 @@ class Find( HISTORICAL_M2M = [ "material_types", "technical_processes", + "periods", "datings", "cultural_attributions", "conservatory_states", @@ -2121,6 +2130,7 @@ class Find( "documents_count", "excavation_ids", "weight_string", + "periods_count" ] UPPER_PERMISSIONS = [ (ContextRecord, "base_finds__context_record_id"), @@ -2207,9 +2217,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 +2948,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 +3261,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 +3835,23 @@ 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 + CURRENT_MODEL_ATTR = "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 @@ -3873,7 +3905,13 @@ class FindInsideContainer(models.Model): for attr in Find.HISTORICAL_M2M: - m2m_changed.connect(m2m_historization_changed, sender=getattr(Find, attr).through) + if attr == "datings": + model = FindDating + post_save.connect(related_historization_changed, sender=FindDating) + post_delete.connect(related_historization_changed, sender=FindDating) + else: + model = getattr(Find, attr).through + m2m_changed.connect(m2m_historization_changed, sender=model) LOCATION_TYPE = [ |
