I want to upload a video via a ModelForm to my view to process it then display the result in the front-end.
My approach is:
models.py
from django.db import models
class Video_upload(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE)
video = models.FileField(blank=True,upload_to=‘static/video/’)
forms.py
from django.db import models
from django import forms
from django.forms import ModelForm
from myapp.models import Video_upload
class VideoUploadForm(ModelForm):
video = forms.FileField(required=False, error_messages = {'invalid':("Video files only")}, widget=forms.FileInput)
class Meta:
model = Video_upload
fields = ['video']
views.py
def main(request):
template = loader.get_template('index.html')
model_db = Model_info.objects.get(id=chosen_model)
if request.POST:
form = VideoUploadForm(request.POST, request.FILES)
# video_form = VideoUploadForm(request.POST,request.FILES)
if form.is_valid():
# get uploaded video
uploaded = form.cleaned_data['video']
v_name = request.FILES['video'].name
[[[[[ ??My question is here??]]]]]
How do I get the video that was uploaded through the form ? I can get its name only.
Notice that I don’t want to store it permenantly, just temporarily until the processing completes and yeild a result.