How to display video of cloudnary in admin panel and play
So, I am using cloudinary in django for video handling. video handling is going very well but i want to display video on admin panel.
models.py
course = models.ForeignKey(Course, on_delete=models.CASCADE, related_name='Course')
public_id = models.CharField(max_length=130, blank=True, null=True)
title = models.CharField(max_length=120)
description = models.TextField(max_length=500, blank=True, null=True)
thumbanil = CloudinaryField(
"image",
blank=True,
null=True,
public_id_prefix=get_public_id_prefix,
display_name=get_display_name,
tags=get_tags
)
video = CloudinaryField(
"video",
blank=True,
null=True,
type='private',
resource_type="video",
public_id_prefix=get_public_id_prefix,
display_name=get_display_name,
tags=get_tags
)
admins.py
import helpers
from cloudinary import CloudinaryImage
from django.contrib import admin
from .models import Course, Lesson
from django.utils.html import format_html
class LessonInline(admin.StackedInline): model = Lesson fields = ['public_id', 'title', 'description', 'thumbanil', 'display_thumbnail' , 'video', 'display_video_content', 'order', 'can_preview', 'status', 'updated', 'timestamp'] readonly_fields = ['public_id', 'updated', 'timestamp', 'display_thumbnail', 'display_video_content']
extra = 0 # means number of empty forms display in admin panel for adding lessons ok.
def display_video_content(self, obj):
url = helpers.get_cloudinary_video_object(
obj,
field_name="video",
as_html=False,
width=400,
height=350,
sign_url=False,
fetch_format="auto",
quality="auto"
)
return format_html(f"<source src='{url}' type='video/mp4' /sourse>")
display_video_content.short_description = 'Current Video'
helper/server.py
def get_cloudinary_video_object(
instance,
field_name="video",
as_html=False,
width=None,
height=None,
sign_url=False, # for private videos
fetch_format="auto",
quality="auto"
):
if not hasattr(instance, field_name):
return ""
video_objest = getattr(instance, field_name) # give the value of instance fielsname if match with inatance
if not video_objest:
return ""
video_options = {
"sign_url": sign_url,
"fetch_format": fetch_format,
"quality": quality,
}
if width is not None:
video_options['width'] = width
if height is not None:
video_options['height'] = height
if height and width:
video_options['crop'] = "limit"
if as_html:
return video_objest.image(**video_options)
url = video_objest.build_url(**video_options)
return url
so tell me how to display video in admin panel
i type so display image using url of video and pass in video tag img tag source tag
but video not display so could you give me example how to i display video.
return format_html(f"<source src='{url}' type='video/mp4' /sourse>")
sorry for my english because is little bit bad.