def add_memory(request, slug):
event = get_object_or_404(Event, slug=slug)<EOL>form = MemoryForm(request.POST or None, request.FILES or None)<EOL>if form.is_valid():<EOL><INDENT>instance = form.save(commit=False)<EOL>instance.user = request.user<EOL>instance.event = event<EOL>instance.save()<EOL>msg = "<STR_LIT>"<EOL>if request.FILES:<EOL><INDENT>photo_list = request.FILES.getlist('<STR_LIT>')<EOL>photo_count = len(photo_list)<EOL>for upload_file in photo_list:<EOL><INDENT>process_upload(upload_file, instance, form, event, request)<EOL><DEDENT>if photo_count > <NUM_LIT:1>:<EOL><INDENT>msg += "<STR_LIT>".format(photo_count)<EOL><DEDENT>else:<EOL><INDENT>msg += "<STR_LIT>".format(photo_count)<EOL><DEDENT><DEDENT>messages.success(request, msg)<EOL>return HttpResponseRedirect('<STR_LIT>')<EOL><DEDENT>return render(request, '<STR_LIT>', {'<STR_LIT>': form, '<STR_LIT>': event})<EOL>
Adds a memory to an event.