Exesize

Форк
0
/
models.py 
113 строк · 4.0 Кб
1
from django.conf import settings
2
from django.db import models
3
from django.utils.translation import gettext_lazy as _
4

5
NULLABLE = {"blank": True, "null": True}
6

7

8
class BaseModel(models.Model):  # base class should subclass 'django.db.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"))
12

13
    class Meta:
14
        abstract = True
15

16
    def delete(self, *args, **kwargs):
17
        self.deleted = True
18
        self.save()
19

20

21
class NewsManager(models.Manager):
22
    def get_queryset(self):
23
        return super().get_queryset().filter(deleted=False)
24

25

26
class News(BaseModel):
27
    objects = NewsManager()
28
    DoesNotExist = models.Manager
29

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"))
34

35
    def __str__(self) -> str:
36
        return f"{self.pk} {self.title}"
37

38
    class Meta:
39
        ordering = ("-created_at", "-updated_at")
40
        verbose_name = "новость"
41
        verbose_name_plural = "новости"
42

43

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"))
50

51
    def __str__(self) -> str:
52
        return f"{self.pk} {self.name}"
53

54
    class Meta:
55
        verbose_name = "курс"
56
        verbose_name_plural = "курсы"
57

58

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)
65

66
    def __str__(self) -> str:
67
        return f"{self.course.name} | {self.num} | {self.title}"
68

69
    class Meta:
70
        ordering = ("course", "num")
71
        verbose_name = "урок"
72
        verbose_name_plural = "уроки"
73

74

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"))
80

81
    def __str__(self) -> str:
82
        return f"{self.pk} {self.name_second} {self.name_first}"
83

84
    class Meta:
85
        verbose_name = "CourseTeacher"
86

87

88
class CourseFeedback(BaseModel):
89
    RAITING_FIVE = 5
90
    RAITING_FOUR = 4
91
    RAITING_THREE = 3
92
    RAITING_TWO = 2
93
    RAITING_ONE = 1
94

95
    RATINGS = (
96
        (RAITING_FIVE, '⭐⭐⭐⭐⭐'),
97
        (RAITING_FOUR, '⭐⭐⭐⭐'),
98
        (RAITING_THREE, '⭐⭐⭐'),
99
        (RAITING_TWO, '⭐⭐'),
100
        (RAITING_ONE, '⭐'),
101
    )
102

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'))
107

108
    class Meta:
109
        verbose_name = 'Рейтинг'
110
        verbose_name_plural = 'Рейтинги'
111

112
    def __str__(self):
113
        return f'Отзыв о курсе {self.course} от {self.user} '
114

115

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.