diff options
Diffstat (limited to 'ishtar_common/models.py')
-rw-r--r-- | ishtar_common/models.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/ishtar_common/models.py b/ishtar_common/models.py index a5e666b13..e05bcad2d 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -3237,6 +3237,16 @@ def text_format(text, text_format): class BiographicalNote(BaseHistorizedItem, ValueGetter, MainItem): SLUG = "biographicalnote" denomination = models.TextField(_("Denomination")) + slug = models.SlugField( + _("Textual ID"), + max_length=300, + help_text=_( + "The slug is the standardized version of the name. It contains " + "only lowercase letters, numbers and hyphens. Each slug must " + "be unique." + ), + blank=True, + ) last_name = models.TextField(_("Last name"), blank=True, default="") first_name = models.TextField(_("First name"), blank=True, default="") birth_year = models.PositiveIntegerField(_("Year of birth"), blank=True, null=True) @@ -3267,6 +3277,29 @@ class BiographicalNote(BaseHistorizedItem, ValueGetter, MainItem): def __str__(self): return self.denomination + def history_compress(self): + return self.slug + + @classmethod + def history_decompress(cls, full_value, create=False): + if not full_value: + return [] + res = [] + for value in full_value: + try: + res.append(cls.objects.get(slug=value)) + except cls.DoesNotExist: + continue + return res + + def set_slug(self): + self.slug = create_slug(self.__class__, self.denomination, max_length=250, pk=self.pk) + + def save(self, *args, **kwargs): + if not self.slug: + self.set_slug() + return super().save(*args, **kwargs) + GDPR_ACTIVITY = ( ("DC", _("Directory consultation")), |