diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2024-08-29 17:22:48 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2024-09-05 16:09:19 +0200 |
commit | 1720a9a24b4d53cd4d5981f1b847bd3642fa6fae (patch) | |
tree | f3fa122ebc9f98091a9511abff79088de71c299d /archaeological_finds/models_finds.py | |
parent | f38be838170e93c60c7f7cd1f1d0f7c0fd0cf2fa (diff) | |
download | Ishtar-1720a9a24b4d53cd4d5981f1b847bd3642fa6fae.tar.bz2 Ishtar-1720a9a24b4d53cd4d5981f1b847bd3642fa6fae.zip |
✨ manage find localization history
Diffstat (limited to 'archaeological_finds/models_finds.py')
-rw-r--r-- | archaeological_finds/models_finds.py | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/archaeological_finds/models_finds.py b/archaeological_finds/models_finds.py index 68c988517..55219d452 100644 --- a/archaeological_finds/models_finds.py +++ b/archaeological_finds/models_finds.py @@ -2260,6 +2260,7 @@ class Find( related_name="finds", blank=True, help_text=_("Related treatments when no new find is created"), + through="FindTreatment" ) cached_periods = models.TextField( _("Cached periods label"), @@ -3553,6 +3554,56 @@ for attr in Find.HISTORICAL_M2M: m2m_changed.connect(m2m_historization_changed, sender=getattr(Find, attr).through) +LOCATION_TYPE = [ + ["C", _("Current")], + ["R", _("Reference")], + ["B", _("Both")], +] + + +class FindTreatment(models.Model): + """ + Record all new location for a find. + """ + find = models.ForeignKey( + Find, + verbose_name=_("Find"), + on_delete=models.CASCADE, + ) + treatment = models.ForeignKey( + "archaeological_finds.Treatment", + blank=True, null=True, + on_delete=models.CASCADE + ) + full_location = models.TextField(_("Full location"), default="", blank=True) + location_type = models.CharField(_("Location type"), max_length=1, choices=LOCATION_TYPE, + default="C") + + class Meta: + verbose_name = _("Find - Treatment") + verbose_name_plural = _("Find - Treatments") + db_table = 'archaeological_finds_find_treatments' + + def generate_full_location(self): + if getattr(self, "_full_location_set", False) or self.full_location or ( + not self.treatment.is_current_container_changer and + not self.treatment.is_reference_container_changer): + return + if self.treatment.is_current_container_changer: + if self.treatment.is_reference_container_changer: + self.location_type = "B" + else: + self.location_type = "C" + elif self.treatment.is_reference_container_changer: + self.location_type = "R" + if self.treatment.container: + self.full_location = self.treatment.container.generate_full_location() + elif self.treatment.is_loan: + self.full_location = self.container_ref.generate_full_location() + self._full_location_set = True + self.save() + + class Property(LightHistorizedItem): find = models.ForeignKey(Find, verbose_name=_("Find"), on_delete=models.CASCADE) administrative_act = models.ForeignKey( |