summaryrefslogtreecommitdiff
path: root/ishtar_common/models.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2024-02-26 11:41:41 +0100
committerÉtienne Loks <etienne.loks@iggdrasil.net>2024-04-16 16:42:32 +0200
commit50dd359c1981bd4136c9dedf7a147bed9c1b47bf (patch)
tree1a328ff8a6f97f06bd2d5d4f8990694136037a7b /ishtar_common/models.py
parenta634566637d52380f1289be46bdcfd9e636f31af (diff)
downloadIshtar-50dd359c1981bd4136c9dedf7a147bed9c1b47bf.tar.bz2
Ishtar-50dd359c1981bd4136c9dedf7a147bed9c1b47bf.zip
🗃️ add slug to biographical notes
Diffstat (limited to 'ishtar_common/models.py')
-rw-r--r--ishtar_common/models.py33
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")),