|
|
|
@ -1,4 +1,5 @@ |
|
|
|
import arrow |
|
|
|
import arrow |
|
|
|
|
|
|
|
from random import shuffle |
|
|
|
from uuid import uuid4 |
|
|
|
from uuid import uuid4 |
|
|
|
from django.db import models |
|
|
|
from django.db import models |
|
|
|
from django.core.exceptions import ValidationError |
|
|
|
from django.core.exceptions import ValidationError |
|
|
|
@ -98,7 +99,7 @@ class Course(BaseModel, DeactivatedMixin): |
|
|
|
class Meta: |
|
|
|
class Meta: |
|
|
|
verbose_name = 'Курс' |
|
|
|
verbose_name = 'Курс' |
|
|
|
verbose_name_plural = 'Курсы' |
|
|
|
verbose_name_plural = 'Курсы' |
|
|
|
ordering = ['-created_at'] |
|
|
|
ordering = ['-is_featured', ] |
|
|
|
|
|
|
|
|
|
|
|
def __str__(self): |
|
|
|
def __str__(self): |
|
|
|
return str(self.id) + ' ' + self.title |
|
|
|
return str(self.id) + ' ' + self.title |
|
|
|
@ -149,6 +150,24 @@ class Course(BaseModel, DeactivatedMixin): |
|
|
|
def count_videos_in_lessons(self): |
|
|
|
def count_videos_in_lessons(self): |
|
|
|
return Video.objects.filter(lesson__in=self.lessons.all()).count() |
|
|
|
return Video.objects.filter(lesson__in=self.lessons.all()).count() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@classmethod |
|
|
|
|
|
|
|
def shuffle(cls, qs, order_is_featured = True): |
|
|
|
|
|
|
|
if order_is_featured: |
|
|
|
|
|
|
|
featured = [] |
|
|
|
|
|
|
|
other = [] |
|
|
|
|
|
|
|
for c in list(qs): |
|
|
|
|
|
|
|
if c.is_featured: |
|
|
|
|
|
|
|
featured.append(c) |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
other.append(c) |
|
|
|
|
|
|
|
shuffle(featured) |
|
|
|
|
|
|
|
shuffle(other) |
|
|
|
|
|
|
|
return featured + other |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
all = list(qs) |
|
|
|
|
|
|
|
shuffle(all) |
|
|
|
|
|
|
|
return all |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Category(models.Model): |
|
|
|
class Category(models.Model): |
|
|
|
title = models.CharField('Название категории', max_length=100) |
|
|
|
title = models.CharField('Название категории', max_length=100) |
|
|
|
|