1
from django.conf import settings
2
from django.db import models
3
from django.utils.translation import gettext_lazy as _
5
NULLABLE = {"blank": True, "null": True}
8
class BaseModel(models.Model):
9
created_at = models.DateTimeField(auto_now_add=True, verbose_name=_("created_at"), editable=False)
10
updated_at = models.DateTimeField(auto_now=True, verbose_name="_(updated_at)", editable=False)
11
deleted = models.BooleanField(default=False, verbose_name=_("deleted"))
16
def delete(self, *args, **kwargs):
21
class NewsManager(models.Manager):
22
def get_queryset(self):
23
return super().get_queryset().filter(deleted=False)
27
objects = NewsManager()
28
DoesNotExist = models.Manager
30
title = models.CharField(max_length=256, verbose_name="title")
31
preambule = models.CharField(max_length=1024, verbose_name=_("preambule"))
32
body = models.TextField(blank=True, null=True, verbose_name=_("body"))
33
body_as_markdown = models.BooleanField(default=False, verbose_name=_("as markdown"))
35
def __str__(self) -> str:
36
return f"{self.pk} {self.title}"
39
ordering = ("-created_at", "-updated_at")
40
verbose_name = "новость"
41
verbose_name_plural = "новости"
44
class Courses(BaseModel):
45
name = models.CharField(max_length=256, verbose_name=_("name"))
46
description = models.TextField(verbose_name=_("description"), **NULLABLE)
47
description_as_markdown = models.BooleanField(verbose_name=_("as markdown"), default=False)
48
cost = models.DecimalField(max_digits=8, decimal_places=2, verbose_name=_("cost"), default=0)
49
cover = models.CharField(max_length=25, default="no_image.svg", verbose_name=_("cover"))
51
def __str__(self) -> str:
52
return f"{self.pk} {self.name}"
56
verbose_name_plural = "курсы"
59
class Lesson(BaseModel):
60
course = models.ForeignKey(Courses, on_delete=models.CASCADE, **NULLABLE)
61
num = models.PositiveIntegerField(verbose_name=_("lesson number"))
62
title = models.CharField(max_length=256, verbose_name="Name")
63
description = models.TextField(verbose_name=_("description"), **NULLABLE)
64
description_as_markdown = models.BooleanField(verbose_name=_("as markdown"), default=False)
66
def __str__(self) -> str:
67
return f"{self.course.name} | {self.num} | {self.title}"
70
ordering = ("course", "num")
72
verbose_name_plural = "уроки"
75
class CourseTeachers(BaseModel):
76
course = models.ManyToManyField(Courses)
77
name_first = models.CharField(max_length=128, verbose_name=_("name"))
78
name_second = models.CharField(max_length=128, verbose_name=_("surname"))
79
day_birth = models.DateField(verbose_name=_("day_birth"))
81
def __str__(self) -> str:
82
return f"{self.pk} {self.name_second} {self.name_first}"
85
verbose_name = "CourseTeacher"
88
class CourseFeedback(BaseModel):
96
(RAITING_FIVE, '⭐⭐⭐⭐⭐'),
97
(RAITING_FOUR, '⭐⭐⭐⭐'),
98
(RAITING_THREE, '⭐⭐⭐'),
103
course = models.ForeignKey(Courses, on_delete=models.CASCADE, verbose_name=_('course'))
104
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, verbose_name=_('user'))
105
feedback = models.TextField(verbose_name='Отзыв', default=_('empty'))
106
rating = models.PositiveSmallIntegerField(choices=RATINGS, default=RAITING_FIVE, verbose_name=_('rating'))
109
verbose_name = 'Рейтинг'
110
verbose_name_plural = 'Рейтинги'
113
return f'Отзыв о курсе {self.course} от {self.user} '