I have a query regarding my colleague's code. The code is functioning properly and it displays some images that were previously uploaded via an input through a modal. However, I am facing an issue as I would like to showcase all 10 images in a detailed view. After attempting to modify the code, I am only able to display one image out of the 10 that were uploaded. How can I ensure that all 10 images are displayed? I am unfamiliar with how to work with the JSON structure that was utilized.
views.py
class detail_carro(DetailView):
template_name = 'carros/carros-detail.html'
queryset=Carro.objects.all()
context_object_name = 'carros'
def create_carros_picture(request):
if request.FILES['files']:
file = request.FILES['files']
fs = FileSystemStorage()
new_name = "picture"
new_name = fs.get_valid_name(new_name)+".jpg"
filename = fs.save(new_name, file)
return JsonResponse({filename:file.name},safe=False)
else:
form=CarroForm()
return render(request, "carros/carros-form-add.html",{'form':form})
def create_carros_warranty(request):
if request.FILES['files']:
file = request.FILES['files']
fs = FileSystemStorage()
ext = file.name.split('.')[-1]
new_name = "warranty"
new_name = fs.get_valid_name(new_name) + '.' + ext
filename = fs.save(new_name, file)
return JsonResponse({filename: file.name}, safe=False)
else:
form = CarroForm()
return render(request, "carros/carros-form-add.html", {'form': form})
carros-detail.html
{% if carros.new_name %}
<a data-id="{{carros.id}}" class="btn_view_gallery">
<img src="{% get_media_prefix %}{{carros.new_name}}" height="300">
</a>
{% endif %}