Allow duplicate gallery names

This commit is contained in:
krek0 2026-04-22 13:44:18 +02:00
parent 0c42aa321d
commit cc108a8dcd
3 changed files with 26 additions and 8 deletions

View file

@ -120,12 +120,6 @@ class UploadForm(forms.Form):
Submit("submit", _("Upload"), css_class="btn btn-success mt-2"),
)
def clean_new_gallery_title(self):
title = self.cleaned_data["new_gallery_title"]
if title and Gallery.objects.filter(title=title).exists():
raise forms.ValidationError(_("A gallery with that title already exists."))
return title
def clean(self):
cleaned_data = super().clean()
@ -148,9 +142,15 @@ class UploadForm(forms.Form):
if not gallery:
# Create new gallery
title = self.cleaned_data.get("new_gallery_title")
base_slug = slugify(title)
slug = base_slug
counter = 2
while Gallery.objects.filter(slug=slug).exists():
slug = f"{base_slug}-{counter}"
counter += 1
gallery = Gallery.objects.create(
title=title,
slug=slugify(title),
slug=slug,
date_start=self.cleaned_data["new_gallery_date_start"],
date_end=self.cleaned_data["new_gallery_date_end"],
description=self.cleaned_data["new_gallery_description"],