Commit 8ca3e461 authored by Eduardo Nunes's avatar Eduardo Nunes
Browse files

Adding translation into VideoFile model

parent 4c644b7d
# Generated by Django 2.2.24 on 2021-07-27 14:45
import courses.videos.models
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('courses', '0030_videofile'),
]
operations = [
migrations.AddField(
model_name='videofile',
name='file_en',
field=models.FileField(default=None, null=True, upload_to=courses.videos.models.get_upload_path),
),
migrations.AddField(
model_name='videofile',
name='file_es',
field=models.FileField(default=None, null=True, upload_to=courses.videos.models.get_upload_path),
),
migrations.AddField(
model_name='videofile',
name='file_pt_br',
field=models.FileField(default=None, null=True, upload_to=courses.videos.models.get_upload_path),
),
migrations.AddField(
model_name='videofile',
name='name_en',
field=models.CharField(max_length=255, null=True),
),
migrations.AddField(
model_name='videofile',
name='name_es',
field=models.CharField(max_length=255, null=True),
),
migrations.AddField(
model_name='videofile',
name='name_pt_br',
field=models.CharField(max_length=255, null=True),
),
migrations.AddField(
model_name='videofile',
name='video_en',
field=models.OneToOneField(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='file', to='courses.Video', verbose_name='file'),
),
migrations.AddField(
model_name='videofile',
name='video_es',
field=models.OneToOneField(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='file', to='courses.Video', verbose_name='file'),
),
migrations.AddField(
model_name='videofile',
name='video_pt_br',
field=models.OneToOneField(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='file', to='courses.Video', verbose_name='file'),
),
]
......@@ -2,6 +2,7 @@ from modeltranslation.translator import register, TranslationOptions
from .models import Course, Lesson, Unit, ProfessorMessage
from .course_material.models import CourseMaterial, File
from .stats.models import AccessibleArea
from .videos.models import VideoFile
from .certification.models import CertificateTemplate
......@@ -49,3 +50,7 @@ class CertificateTemplateTranslationOptions(TranslationOptions):
'base_logo', 'signature', 'second_signature', 'site_logo',
'organization_name', 'text')
@register(VideoFile)
class VideoFileTranslationOptions(TranslationOptions):
fields = ('name', 'file', 'video')
from rest_framework import serializers
from modeltranslation.utils import fallbacks
from .models import Video, VideoFile
......@@ -9,6 +9,12 @@ class VideoFileSerializer(serializers.ModelSerializer):
model = VideoFile
fields = ('id', 'name', 'video', 'file')
def get_file(self, obj):
with fallbacks(False):
files = VideoFileSerializer(required=False, allow_null=True, read_only=True, **{'context': self.context}).data
files = [f for f in files if f['file'] != None]
return files
class VideoSerializer(serializers.ModelSerializer):
......@@ -16,4 +22,8 @@ class VideoSerializer(serializers.ModelSerializer):
model = Video
fields = ('id', 'name', 'youtube_id', 'file')
file = VideoFileSerializer(required=False, allow_null=True, read_only=True)
def get_file(self, obj):
with fallbacks(False):
files = VideoFileSerializer(required=False, allow_null=True, read_only=True, **{'context': self.context}).data
files = [f for f in files if f['file'] != None]
return files
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