Allow duplicate gallery names
This commit is contained in:
parent
0c42aa321d
commit
cc108a8dcd
3 changed files with 26 additions and 8 deletions
|
|
@ -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"],
|
||||
|
|
|
|||
18
photologue/migrations/0006_allow_duplicate_gallery_titles.py
Normal file
18
photologue/migrations/0006_allow_duplicate_gallery_titles.py
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 6.0.4 on 2026-04-22 10:58
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('photologue', '0005_add_can_resolve_censorship_permission'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='gallery',
|
||||
name='title',
|
||||
field=models.CharField(max_length=250, verbose_name='title'),
|
||||
),
|
||||
]
|
||||
|
|
@ -145,7 +145,7 @@ class TagField(models.CharField):
|
|||
|
||||
|
||||
class Gallery(models.Model):
|
||||
title = models.CharField(_("title"), max_length=250, unique=True)
|
||||
title = models.CharField(_("title"), max_length=250)
|
||||
slug = models.SlugField(
|
||||
_("title slug"),
|
||||
unique=True,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue