Have a working app that allows the user to upload multiple files (typically images) at once, but if they upload more than a few files at once, or very large files, it takes very long to go through and they're stuck on the form template waiting while this is happening.
I can tell that what I'm doing isn't very efficient but I'm not sure how to make it better/faster. Am new to django/python, thanks for any help.
views.py:
def add_event(request):
form = EventFullForm(request.POST or None, request.FILES or None)
files = request.FILES.getlist('images')
if request.method == "POST":
if form.is_valid():
user = request.user
title = form.cleaned_data['title']
description = form.cleaned_data['description']
start_time = form.cleaned_data['start_time']
end_time = form.cleaned_data['end_time']
event_obj = Event.objects.create(user=user, title=title, description=description, start_time=start_time,
end_time=end_time)
for f in files:
Images.objects.create(event=event_obj, image=f)
return redirect('calendarapp:calendar')
else:
form = EventFullForm()
context = {'form': form, 'files': files}
return render(request, 'calendarapp/test_form.html', context)
Please let me know if sharing any additional code would be helpful