summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2024-01-16 17:42:04 +0100
committerÉtienne Loks <etienne.loks@iggdrasil.net>2024-01-16 17:42:04 +0100
commit12732abd84d03d4472ee5f52688f776d98ad29ec (patch)
treecfd60f7f2f3c7866a6f8b6f068cb980eb1286603
parent9db17bf07d46cbe157409f4f817392e28b28489a (diff)
downloadIshtar-12732abd84d03d4472ee5f52688f776d98ad29ec.tar.bz2
Ishtar-12732abd84d03d4472ee5f52688f776d98ad29ec.zip
🐛 area: fix automatic slug generation (refs #5715)
-rw-r--r--ishtar_common/models_common.py18
1 files changed, 17 insertions, 1 deletions
diff --git a/ishtar_common/models_common.py b/ishtar_common/models_common.py
index 0345eada2..bde457a3c 100644
--- a/ishtar_common/models_common.py
+++ b/ishtar_common/models_common.py
@@ -629,6 +629,22 @@ class GeneralType(Cached, models.Model):
):
yield child
+ def set_txt_idx(self):
+ base_q = self.__class__.objects
+ if self.pk:
+ base_q = base_q.exclude(pk=self.pk)
+ count, txt_idx = True, None
+ idx = 0
+ while count:
+ if not txt_idx:
+ txt_idx = slugify(self.label)[:100]
+ else:
+ txt_idx = txt_idx[:-5] + f"{idx:05d}"
+ q = base_q.filter(txt_idx=txt_idx)
+ count = q.count()
+ idx += 1
+ self.txt_idx = txt_idx
+
def save(self, *args, **kwargs):
ItemKey = apps.get_model("ishtar_common", "ItemKey")
if not self.id and not self.label:
@@ -638,7 +654,7 @@ class GeneralType(Cached, models.Model):
self.txt_idx = txt_idx
self.label = " ".join(" ".join(self.txt_idx.split("-")).split("_")).title()
if not self.txt_idx:
- self.txt_idx = slugify(self.label)[:100]
+ self.set_txt_idx()
# clean old keys
if self.pk: