diff --git a/AKModel/models.py b/AKModel/models.py index cc7d36b04d9a3b6dd1c6a3bc8ddc8c593bebf4e9..2f1f9ad821ab4c63b3126fe1760857f2fd037411 100644 --- a/AKModel/models.py +++ b/AKModel/models.py @@ -72,7 +72,7 @@ class AKOwner(models.Model): if not AKOwner.objects.filter(slug=slug_candidate).exists(): break digits = len(str(i)) - slug_candidate = '{}-{}'.format(slug_candidate[:-digits + 1], i) + slug_candidate = '{}-{}'.format(slug_candidate[:-(digits + 1)], i) self.slug = slug_candidate diff --git a/AKSubmission/forms.py b/AKSubmission/forms.py index 3dff6f1bc40623657e8fc2ebefeaa7acd38892cd..1a3689136ad08e62ab3ae25d87bd5be48932cf8c 100644 --- a/AKSubmission/forms.py +++ b/AKSubmission/forms.py @@ -1,3 +1,5 @@ +import itertools + from django import forms from django.core.exceptions import ValidationError from django.utils.translation import ugettext_lazy as _ @@ -76,6 +78,14 @@ class AKForm(forms.ModelForm): short_name = short_name.partition(':')[0] short_name = short_name.partition(' - ')[0] short_name = short_name.partition(' (')[0] + for i in itertools.count(1): + if not AK.objects.filter(short_name=short_name, event=self.cleaned_data["event"]).exists(): + break + print(short_name) + digits = len(str(i)) + print(digits) + short_name = '{}-{}'.format(short_name[:-(digits + 1)], i) + print(short_name) cleaned_data["short_name"] = short_name[:AK._meta.get_field('short_name').max_length] # Get tag names from raw tags