.
This commit is contained in:
@@ -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')
|
||||
|
||||
Reference in New Issue
Block a user