def post(self, request, *args, **kwargs): store = self.get_object() form = UploadFileForm(request.POST, request.FILES) if form.is_valid(): store.handle_uploaded_file(request.FILES['file']) return redirect(store) return redirect('stores:file_upload', pk=pk)
def upload_file(request, pk): """Simple FBV example""" store = get_object_or_404(Store, pk=pk) if request.method == 'POST': # Don't forget to add request.FILES! form = UploadFileForm(request.POST, request.FILES) if form.is_valid(): store.handle_uploaded_file(request.FILES['file']) return redirect(store) else: form = UploadFileForm() return render(request, 'upload.html', {'form': form, 'store': store})
def get(self, request, *args, **kwargs): store = self.get_object() form = UploadFileForm() return render( request, 'upload.html', {'form': form, 'store': store})