Add/remove/change image on box detail page added
All checks were successful
Build containers when image tags change / build-if-image-changed (., web, containers, main container, git.baumann.gr/adebaumann/labhelper) (push) Successful in 25s
Build containers when image tags change / build-if-image-changed (data-loader, loader, initContainers, init-container, git.baumann.gr/adebaumann/labhelper-data-loader) (push) Successful in 6s

This commit is contained in:
2026-01-01 13:48:09 +01:00
parent c566e31ab5
commit 10cc24ff03
4 changed files with 64 additions and 10 deletions

View File

@@ -3,7 +3,7 @@ from django.db.models import Q
from django.http import HttpResponse, JsonResponse
from django.shortcuts import get_object_or_404, redirect, render
from .forms import ThingFormSet
from .forms import ThingFormSet, ThingPictureForm
from .models import Box, Thing, ThingType
@@ -44,20 +44,38 @@ def thing_detail(request, thing_id):
Thing.objects.select_related('thing_type', 'box', 'box__box_type'),
pk=thing_id
)
boxes = Box.objects.select_related('box_type').all().order_by('id')
picture_form = ThingPictureForm(instance=thing)
if request.method == 'POST':
new_box_id = request.POST.get('new_box')
if new_box_id:
new_box = get_object_or_404(Box, pk=new_box_id)
thing.box = new_box
thing.save()
action = request.POST.get('action')
if action == 'move':
new_box_id = request.POST.get('new_box')
if new_box_id:
new_box = get_object_or_404(Box, pk=new_box_id)
thing.box = new_box
thing.save()
return redirect('thing_detail', thing_id=thing.id)
elif action == 'upload_picture':
picture_form = ThingPictureForm(request.POST, request.FILES, instance=thing)
if picture_form.is_valid():
picture_form.save()
return redirect('thing_detail', thing_id=thing.id)
elif action == 'delete_picture':
if thing.picture:
thing.picture.delete()
thing.picture = None
thing.save()
return redirect('thing_detail', thing_id=thing.id)
return render(request, 'boxes/thing_detail.html', {
'thing': thing,
'boxes': boxes,
'picture_form': picture_form,
})