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.
 
 

71 lines
2.7 KiB

from django.db import models
class VideoCollection(models.Model):
title = models.CharField(max_length=255, help_text="This title will not be displayed anywhere")
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 = FilerImageField(related_name="+", on_delete=models.SET_NULL, null=True, blank=True, help_text=_(
'image allowed'
))
description = models.TextField(null=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'))
download_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
class Meta:
verbose_name = _('Video')
verbose_name_plural = _('Videos')