Stay on form after adding things

This commit is contained in:
2025-12-28 22:58:01 +01:00
parent f6a953158d
commit 805510c0f6
2 changed files with 11 additions and 8 deletions

View File

@@ -62,6 +62,8 @@ def add_things(request, box_id):
"""Add multiple things to a box at once."""
box = get_object_or_404(Box, pk=box_id)
success_message = None
if request.method == 'POST':
formset = ThingFormSet(request.POST)
@@ -73,17 +75,12 @@ def add_things(request, box_id):
thing.box = box
thing.save()
created_count += 1
print(f'DEBUG: created_count={created_count}')
if created_count > 0:
print(f'DEBUG: Redirecting to box_detail with box_id={box_id}')
return redirect('box_detail', box_id=box_id)
else:
print('DEBUG: No valid data submitted')
else:
formset = ThingFormSet()
success_message = f'Added {created_count} thing{"s" if created_count > 1 else ""} successfully.'
formset = ThingFormSet()
return render(request, 'boxes/add_things.html', {
'box': box,
'formset': formset,
'success_message': success_message,
})