Initial file uploding w/ new "files" app
This commit is contained in:
19
apps/files/views.py
Normal file
19
apps/files/views.py
Normal file
@ -0,0 +1,19 @@
|
||||
from django.shortcuts import render
|
||||
from django.http import JsonResponse
|
||||
from django.views.generic import CreateView
|
||||
|
||||
from .forms import FileForm
|
||||
from .models import File
|
||||
|
||||
class FileUploadView(CreateView):
|
||||
model = File
|
||||
form_class = FileForm
|
||||
|
||||
def form_valid(self, form):
|
||||
# save the File to the database
|
||||
super().form_valid(form)
|
||||
|
||||
return JsonResponse({'is_valid': True, 'url': self.object.file.url})
|
||||
|
||||
def form_invalid(self, form):
|
||||
return JsonResponse({'is_valid': False, 'errors': form.errors})
|
Reference in New Issue
Block a user