feature/boxform #2

Merged
adebaumann merged 3 commits from feature/boxform into master 2025-12-28 22:12:07 +00:00
2 changed files with 11 additions and 8 deletions
Showing only changes of commit 805510c0f6 - Show all commits

View File

@@ -210,6 +210,12 @@
</table>
</form>
{% endif %}
{% if success_message %}
<div class="success-message">
{{ success_message }}
</div>
{% endif %}
</div>
</body>
</html>

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,
})