From c0d5b619328af285787f76d296c61cce35bdf243 Mon Sep 17 00:00:00 2001 From: Lukas Winkler Date: Sun, 14 Jun 2020 16:21:39 +0200 Subject: [PATCH] fix clean on edit --- acros/models/Acronym.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/acros/models/Acronym.py b/acros/models/Acronym.py index 9e191c4..67b6908 100644 --- a/acros/models/Acronym.py +++ b/acros/models/Acronym.py @@ -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")