Commit c6c0adc3 authored by Ilya Simonov's avatar Ilya Simonov

add new fiels in Video model

parent 7999e802
No preview for this file type
No preview for this file type
......@@ -4,8 +4,13 @@ from . import models
class VideoAdmin(admin.ModelAdmin):
list_display = ['id', 'title', ]
list_display = ['id', 'title', 'slug', 'status', 'duration']
readonly_fields = ['created', 'updated']
list_filter = ('status',)
def save_model(self, request, obj, form, change):
obj.creator = request.user
super().save_model(request, obj, form, change)
class PlayListAdmin(admin.ModelAdmin):
......
# Generated by Django 4.1.7 on 2023-02-28 15:22
# Generated by Django 4.1.7 on 2023-03-06 13:56
import apps.core.utils
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import storages.backends.s3boto3
class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('core', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='video',
name='closed_captions',
field=models.CharField(blank=True, max_length=255, null=True, verbose_name='closed_captions'),
),
migrations.AddField(
model_name='video',
name='creator',
field=models.ForeignKey(blank=True, default=1, on_delete=django.db.models.deletion.CASCADE, related_name='creator_video', to=settings.AUTH_USER_MODEL, verbose_name='creator'),
preserve_default=False,
),
migrations.AddField(
model_name='video',
name='description',
field=models.TextField(blank=True, null=True, verbose_name='description'),
),
migrations.AddField(
model_name='video',
name='duration',
field=models.IntegerField(blank=True, null=True, verbose_name='duration'),
),
migrations.AddField(
model_name='video',
name='slug',
field=models.SlugField(blank=True, max_length=255, unique=True, verbose_name='slug'),
),
migrations.AddField(
model_name='video',
name='status',
field=models.CharField(choices=[('ready', 'Ready'), ('progress', 'Progress'), ('fail', 'Fail')], default='progress', max_length=255, verbose_name='status'),
),
migrations.AddField(
model_name='video',
name='thumbnail',
......@@ -32,6 +61,11 @@ class Migration(migrations.Migration):
name='s3_file',
field=models.FileField(blank=True, max_length=500, null=True, storage=storages.backends.s3boto3.S3Boto3Storage(bucket_name='clutchpoints-videos'), upload_to='', verbose_name='AWS S3 file'),
),
migrations.AlterField(
model_name='video',
name='title',
field=models.CharField(max_length=255, verbose_name='title'),
),
migrations.CreateModel(
name='Playlist',
fields=[
......
from django.db import models
from django.utils.translation import gettext_lazy as _
from django.contrib.auth.models import User
from pytils.translit import slugify
from storages.backends.s3boto3 import S3Boto3Storage
from .utils import asset_upload
READY = 'ready'
PROGRESS = 'progress'
FAIL = 'fail'
STATUS_CHOICES = (
(READY, 'Ready'),
(PROGRESS, 'Progress'),
(FAIL, 'Fail'),
)
class BaseModel(models.Model):
updated = models.DateTimeField(_('updated'), auto_now=True, db_index=True)
created = models.DateTimeField(_('created'), auto_now_add=True, db_index=True)
......@@ -15,29 +28,50 @@ class BaseModel(models.Model):
class Video(BaseModel):
title = models.CharField(_('full name'), max_length=255)
title = models.CharField(_('title'), max_length=255)
slug = models.SlugField(_('slug'), max_length=255, unique=True, blank=True)
description = models.TextField(_('description'), blank=True, null=True)
local_file = models.FileField(
'local file',
_('local file'),
upload_to='videos',
blank=True,
null=True,
)
s3_file = models.FileField(
'AWS S3 file',
_('AWS S3 file'),
storage=S3Boto3Storage(bucket_name='clutchpoints-videos'),
blank=True,
null=True,
max_length=500,
)
thumbnail = models.ImageField(
'thumbnail',
_('thumbnail'),
upload_to=asset_upload,
storage=S3Boto3Storage(bucket_name='clutchpoints-videos'),
blank=True,
null=True,
max_length=500,
)
creator = models.ForeignKey(
User,
verbose_name=_('creator'),
related_name='creator_video',
on_delete=models.CASCADE,
blank=True
)
status = models.CharField(
_('status'),
choices=STATUS_CHOICES,
default=PROGRESS,
max_length=255,
)
duration = models.IntegerField(_('duration'), blank=True, null=True)
closed_captions = models.CharField(
_('closed_captions'),
max_length=255,
blank=True,
null=True,
)
class Meta:
ordering = ('title',)
......@@ -45,6 +79,13 @@ class Video(BaseModel):
def __str__(self):
return self.title
def save(self, *args, **kwargs):
print('save')
if not self.id:
self.slug = slugify(self.title)
super().save(*args, **kwargs)
class Playlist(BaseModel):
title = models.CharField(_('title'), max_length=255)
......
import os
from .models import Video
from .models import Video, READY
from .s3_uploader import upload_file
from cp_video.celery import app
......@@ -16,8 +16,9 @@ def send_video_to_s3():
content = local_video.local_file.read()
local_video.s3_file = upload_file(content, key, 'video/mp4')
local_video.status = READY
local_video.save(update_fields=['s3_file'])
local_video.save(update_fields=['s3_file', 'status'])
os.remove(local_video.local_file.path)
local_videos.update(local_file=None)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment