Skip to content
Snippets Groups Projects
Commit 6ccebcb5 authored by Nadja Geisler's avatar Nadja Geisler :sunny:
Browse files

ensure generated short_name is unique with event

parent 2d9a1b2c
No related branches found
No related tags found
No related merge requests found
...@@ -72,7 +72,7 @@ class AKOwner(models.Model): ...@@ -72,7 +72,7 @@ class AKOwner(models.Model):
if not AKOwner.objects.filter(slug=slug_candidate).exists(): if not AKOwner.objects.filter(slug=slug_candidate).exists():
break break
digits = len(str(i)) digits = len(str(i))
slug_candidate = '{}-{}'.format(slug_candidate[:-digits + 1], i) slug_candidate = '{}-{}'.format(slug_candidate[:-(digits + 1)], i)
self.slug = slug_candidate self.slug = slug_candidate
......
import itertools
from django import forms from django import forms
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
...@@ -76,6 +78,14 @@ class AKForm(forms.ModelForm): ...@@ -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] 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] cleaned_data["short_name"] = short_name[:AK._meta.get_field('short_name').max_length]
# Get tag names from raw tags # Get tag names from raw tags
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment