diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2024-02-26 11:41:41 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2024-02-26 15:20:16 +0100 |
commit | d1890dc252f7f75c8b7dd5166e7fd145f7db5379 (patch) | |
tree | 1b8ad4496714de34a36866f1eb13de78508553cc /ishtar_common/models.py | |
parent | 7f19c3e85b4184f43e23cf212c8ec150bc52a719 (diff) | |
download | Ishtar-d1890dc252f7f75c8b7dd5166e7fd145f7db5379.tar.bz2 Ishtar-d1890dc252f7f75c8b7dd5166e7fd145f7db5379.zip |
🗃️ add slug to biographical notes
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")), |