This commit is contained in:
Ross
2025-12-05 14:09:44 +00:00
parent 132aac6edd
commit df7aa67ce8
32 changed files with 50 additions and 0 deletions
+23
View File
@@ -192,3 +192,26 @@ def cards_bulk_update(request):
# If invalid, re-render the overview with errors
backgrounds = BackgroundImage.objects.all()
return render(request, 'cards/bulk_edit.html', {'formset': formset, 'backgrounds': backgrounds})
def cards_bulk_create_images(request):
"""Create multiple Dinosaur cards from uploaded images (one card per image).
Expects a multipart POST with one or more files in the `images` field.
The card `name` is derived from the filename if not provided.
"""
if request.method != 'POST':
return HttpResponseBadRequest('Only POST allowed')
files = request.FILES.getlist('images')
if not files:
return HttpResponseBadRequest('No images uploaded')
created = []
for f in files:
# derive a friendly name from filename
base = os.path.splitext(getattr(f, 'name', '') or '')[0]
name = base.replace('_', ' ').replace('-', ' ').strip().title() or 'New Dinosaur'
d = Dinosaur(name=name, image=f)
d.save()
created.append(d)
# Redirect back to overview
return redirect('cards:overview')