Simplify filtering gallery by slug

This commit is contained in:
Alexandre Iooss 2021-11-14 09:08:37 +01:00
parent 0d52cdca9e
commit af798e3fcc

View file

@ -19,15 +19,14 @@ class Command(BaseCommand):
if options['all']:
galleries = Gallery.objects.all()
else:
galleries = []
for slug in options['slugs']:
for gallery in Gallery.objects.all():
if gallery.slug == slug:
galleries += [gallery]
break
else:
raise CommandError(
'Slug {} does not correspond to a gallery in the database.'.format(slug))
print('error')
gallery_query = Gallery.objects.filter(slug=slug)
if not gallery_query:
raise CommandError(f"Slug {slug} does not correspond to a "
"gallery in the database.")
galleries += gallery_query
# Find duplicates in all galleries
for gallery in galleries:
duplicates = find_duplicate(gallery)