mirror of
https://github.com/Findus23/acronomy.git
synced 2024-09-19 15:33:45 +02:00
fix clean on edit
This commit is contained in:
parent
77012ee325
commit
c0d5b61932
1 changed files with 8 additions and 7 deletions
|
@ -43,10 +43,11 @@ class Acronym(models.Model):
|
|||
ordering = ["name"]
|
||||
|
||||
def clean(self):
|
||||
new_slug = slugify(self.name)
|
||||
try:
|
||||
found = Acronym.objects.get(slug=new_slug)
|
||||
except Acronym.DoesNotExist:
|
||||
found = False
|
||||
if found:
|
||||
raise ValidationError(f"slug '{new_slug}' already exists")
|
||||
if not self.id:
|
||||
new_slug = slugify(self.name)
|
||||
try:
|
||||
found = Acronym.objects.get(slug=new_slug)
|
||||
except Acronym.DoesNotExist:
|
||||
found = False
|
||||
if found:
|
||||
raise ValidationError(f"slug '{new_slug}' already exists")
|
||||
|
|
Loading…
Reference in a new issue