I am trying to create a video blog where users will be able to upload their videos. I have created view and form to upload the file, and also customized the HTML5 video player followint some tutorials. Now I want add a file uploading progress bar but I can't do it for the shortage of my knowledge in programming. I am trying for the last few days. I have found some very old answers on Stackoverflow but they are very difficult for me to understand. I do not want to use any bootstrap framework because my full demo site has been built without any 3rd party framework. I am using Python 3.6, Django 2.2.5, Postgresql 11 on Ubuntu 18.04. Guys could you please see my codes bellow and help me with the easiest way to solve the problem? Thanks in advance!
Here is the post form:
{% extends 'base.html' %}
{% block content %}
<!-- GRID SYTEM BEGINS -->
<main id="content" class="main-area">
<section class="detail-main-content">
<div class="all-account">
<h1>Create a new post</h1>
<!-- form action should be blank always -->
<form method="POST" action="" enctype="multipart/form-data">
{% csrf_token %}
{{ form.as_p }}
<button type="submit">POST</button>
</form>
</div>
</section>
</main>
{% endblock content %}
Here is the forms.py file:
from django import forms
from .models import Post
class BaseForm(forms.Form):
def __init__(self, *args, **kwargs):
kwargs.setdefault('label_suffix', '')
super(BaseForm, self).__init__(*args, **kwargs)
class BaseModelForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
kwargs.setdefault('label_suffix', '')
super(BaseModelForm, self).__init__(*args, **kwargs)
class PostForm(BaseModelForm):
class Meta:
model = Post
fields = ('title', 'clip', 'description')
class EmailPostForm(BaseForm):
your_name = forms.CharField(max_length=25)
email = forms.EmailField()
to = forms.EmailField()
description = forms.CharField(required=False,
widget=forms.Textarea)
Here is the views.py file:
from django.shortcuts import render, get_object_or_404, redirect
from django.contrib.auth.decorators import login_required
from django.contrib.auth.mixins import LoginRequiredMixin, UserPassesTestMixin
from django.contrib.auth.models import User
from django.utils import timezone
from django.views.generic import (
ListView,
UpdateView,
DeleteView,
)
from . models import Post
from .forms import PostForm, EmailPostForm
@login_required
def post_new(request):
if request.method == "POST":
# without request.FILES file upload field won't work
form = PostForm(request.POST, request.FILES)
if form.is_valid():
post = form.save(commit=False)
post.author = request.user
post.publish = timezone.now()
post.save()
return redirect('post-detail', id=post.id)
else:
form = PostForm()
return render(request, 'vblog/post_new.html', {'form': form})