models.py
from django.db import models
from embed_video.fields import EmbedVideoField
Class Video(models.Model):
title = models.CharField(max_length=30)
description = models.TextField(blank=True)
url = EmbedVideoField(verbose_name=‘video’)
views.py
from django.views.generic.edit import CreateView
from django.views.generic.list import ListView
class VideoCreate(CreateView):
model = Video
form_class = NewVideoForm
class VideoList(ListView):
model = Video
ordering = ["-created"]
forms.py
from django import forms
from .models import Video
class NewVideoForm(forms.ModelForm):
description = forms.CharField(widget=forms.Textarea(),
required=False,
max_length=4000,
help_text='The max length of the text is 4000.')
url = forms.URLField(label='video', help_text='Please enter a Youtube or Vimeo link.')
class Meta:
model = Video
fields = ['title', 'description', 'url']