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.
34 lines
1.2 KiB
34 lines
1.2 KiB
import os
|
|
from django.db import models
|
|
|
|
from filer.fields.image import FilerImageField
|
|
from filer.fields.file import FilerFileField
|
|
|
|
|
|
|
|
def lesson_file_upload_to(instance, filename):
|
|
return os.path.join(f"courses/{instance.course.slug}/lessons/{filename}")
|
|
|
|
|
|
|
|
|
|
class Lesson(models.Model):
|
|
class ContentTypeChoices(models.TextChoices):
|
|
LINK = 'link', 'Link'
|
|
FILE = 'file', 'File'
|
|
|
|
course = models.ForeignKey("course.Course", on_delete=models.CASCADE, related_name='lessons', verbose_name='Course')
|
|
title = models.CharField(max_length=255, verbose_name='Lesson Title')
|
|
priority = models.IntegerField(null=True, blank=True, verbose_name='Priority')
|
|
duration = models.PositiveIntegerField(verbose_name='Duration (in minutes)')
|
|
content_type = models.CharField(max_length=10, choices=ContentTypeChoices.choices, verbose_name='Content Type')
|
|
content_file = models.FileField(
|
|
null=True,
|
|
blank=True,
|
|
upload_to=lesson_file_upload_to,
|
|
)
|
|
video_link = models.CharField(max_length=500, null=True, blank=True, verbose_name='Video Link')
|
|
|
|
def __str__(self):
|
|
return f"{self.course.title} - {self.title}"
|
|
|