You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
101 lines
3.7 KiB
101 lines
3.7 KiB
from django.db import models
|
|
from django.utils.translation import gettext_lazy as _
|
|
from filer.fields.image import FilerImageField
|
|
|
|
|
|
class VideoCategory(models.Model):
|
|
title = models.CharField(max_length=255, verbose_name=_('title'))
|
|
slug = models.SlugField(allow_unicode=True, unique=True, verbose_name=_('slug'))
|
|
|
|
status = models.BooleanField(default=True, verbose_name=_('status'))
|
|
order = models.PositiveIntegerField(default=0, verbose_name=_('order'))
|
|
created_at = models.DateTimeField(auto_now_add=True, verbose_name=_('created at'))
|
|
updated_at = models.DateTimeField(auto_now=True, verbose_name=_('updated at'))
|
|
|
|
def __str__(self):
|
|
return self.title
|
|
|
|
class Meta:
|
|
verbose_name = _('Video Category')
|
|
verbose_name_plural = _('Video Categories')
|
|
ordering = ['order']
|
|
|
|
|
|
class VideoCollection(models.Model):
|
|
title = models.CharField(max_length=255, help_text="This title will not be displayed anywhere")
|
|
status = models.BooleanField(default=True, verbose_name=_('status'))
|
|
created_at = models.DateTimeField(auto_now_add=True, verbose_name=_('created at'))
|
|
updated_at = models.DateTimeField(auto_now=True, verbose_name=_('updated at'))
|
|
videos = models.ManyToManyField(
|
|
"Video",
|
|
through='VideoInCollection',
|
|
related_name='collections',
|
|
verbose_name=_('videos'),
|
|
)
|
|
def __str__(self):
|
|
return f'Collection #{self.id}/{self.title}'
|
|
|
|
class Meta:
|
|
verbose_name = _('Video Collection')
|
|
verbose_name_plural = _('Video Collections')
|
|
|
|
|
|
class VideoInCollection(models.Model):
|
|
video_collection = models.ForeignKey(
|
|
"VideoCollection", on_delete=models.CASCADE, related_name='videos_in_collection', verbose_name=_('video collection')
|
|
)
|
|
video = models.ForeignKey(
|
|
"Video", on_delete=models.CASCADE, related_name='collections_videos', verbose_name=_('video')
|
|
)
|
|
priority = models.PositiveIntegerField(default=0, verbose_name=_('priority'))
|
|
|
|
def __str__(self):
|
|
return f"{self.video_collection.title} - {self.video.title} (Priority: {self.priority})"
|
|
|
|
class Meta:
|
|
verbose_name = _('Video in Collection')
|
|
verbose_name_plural = _('Videos in Collection')
|
|
ordering = ['priority']
|
|
|
|
|
|
class Video(models.Model):
|
|
class vdeo_type(models.TextChoices):
|
|
FILE = 'file'
|
|
YOUTUBE = 'youtube'
|
|
|
|
title = models.CharField(max_length=255, null=True)
|
|
slug = models.SlugField(allow_unicode=True, unique=True)
|
|
thumbnail = models.ImageField(upload_to='book_thumbnails/', null=True, blank=True, help_text=_('image allowed'))
|
|
description = models.TextField(null=True)
|
|
categories = models.ManyToManyField(
|
|
VideoCategory,
|
|
related_name='videos',
|
|
verbose_name=_('categories'),
|
|
blank=True,
|
|
)
|
|
video_type = models.CharField(max_length=255, choices=vdeo_type.choices, default=vdeo_type.FILE)
|
|
video_file = models.FileField(upload_to='video/videos/', null=True, blank=True)
|
|
video_url = models.CharField(max_length=655, null=True, blank=True)
|
|
video_time = models.TimeField()
|
|
|
|
view_count = models.PositiveBigIntegerField(default=0, verbose_name=_('view count'))
|
|
|
|
status = models.BooleanField(default=True, verbose_name=_('status'))
|
|
|
|
created_at = models.DateTimeField(auto_now_add=True, verbose_name=_('created at'))
|
|
updated_at = models.DateTimeField(auto_now=True, verbose_name=_('updated at'))
|
|
|
|
def __str__(self):
|
|
return self.title
|
|
|
|
def increment_view_count(self):
|
|
"""Increment the view count for this video"""
|
|
self.view_count += 1
|
|
self.save(update_fields=['view_count'])
|
|
return self.view_count
|
|
|
|
|
|
class Meta:
|
|
verbose_name = _('Video')
|
|
verbose_name_plural = _('Videos')
|
|
|