diff --git a/api/v1/serializers/course.py b/api/v1/serializers/course.py index bdb1a289..4e558f3a 100644 --- a/api/v1/serializers/course.py +++ b/api/v1/serializers/course.py @@ -110,6 +110,7 @@ class CourseCreateSerializer(DispatchContentMixin, 'from_author', 'cover', 'price', + 'age', 'is_infinite', 'deferred_start_at', 'category', @@ -261,6 +262,7 @@ class CourseSerializer(serializers.ModelSerializer): 'from_author', 'cover', 'price', + 'age', 'is_infinite', 'deferred_start_at', 'category', diff --git a/apps/course/filters.py b/apps/course/filters.py index 827079e6..64596057 100644 --- a/apps/course/filters.py +++ b/apps/course/filters.py @@ -5,7 +5,8 @@ from .models import Course class CourseFilter(django_filters.FilterSet): category = django_filters.CharFilter(field_name='category__title', lookup_expr='iexact') + age = django_filters.ChoiceFilter(field_name='age', choices=Course.AGE_CHOICES) class Meta: model = Course - fields = ['category'] + fields = ['category', 'age'] diff --git a/apps/course/models.py b/apps/course/models.py index 72cfad97..03fd9ed3 100644 --- a/apps/course/models.py +++ b/apps/course/models.py @@ -50,6 +50,23 @@ class Course(BaseModel, DeactivatedMixin): (ARCHIVED, 'Archived'), (DENIED, 'Denied') ) + AGE_LT5 = 1 + AGE_57 = 2 + AGE_79 = 3 + AGE_912 = 4 + AGE_1215 = 5 + AGE_1518 = 6 + AGE_GT18 = 7 + AGE_CHOICES = ( + (0, 'Любой возраст'), + (AGE_LT5, 'до 5'), + (AGE_57, '5-7'), + (AGE_79, '7-9'), + (AGE_912, '9-12'), + (AGE_1215, '12-15'), + (AGE_1518, '15-18'), + (AGE_GT18, 'от 18'), + ) slug = models.SlugField( allow_unicode=True, null=True, blank=True, max_length=100, unique=True, db_index=True, @@ -73,6 +90,7 @@ class Course(BaseModel, DeactivatedMixin): 'Цена курса', help_text='Если цена не выставлена, то курс бесплатный', max_digits=10, decimal_places=2, null=True, blank=True ) + age = models.SmallIntegerField(choices=AGE_CHOICES, default=0) is_infinite = models.BooleanField(default=False) deferred_start_at = models.DateTimeField( 'Отложенный запуск курса', help_text='Заполнить если курс отложенный', diff --git a/apps/course/templates/course/courses.html b/apps/course/templates/course/courses.html index a3277174..2f47675a 100644 --- a/apps/course/templates/course/courses.html +++ b/apps/course/templates/course/courses.html @@ -20,18 +20,35 @@
-
-
{% if category %}{{ category.0 }}{% else %}Категории{% endif %}
+
+
{% if category.0 %}{{ category.0 }}{% else %}Категории{% endif %}
-
-
Все курсы
+
+
Все категории
{% category_items category %}
+
+
+
+
{% if age_name %}{{ age_name }}{% else %}Возраст{% endif %}
+
+
+
Любой возраст
+
+ {% for a in ages %} +
+
{{ a.1 }}
+
+ {% endfor %} +
+
+
+
@@ -40,7 +57,7 @@
{% if page_obj.has_next %} - + {% endif %}
diff --git a/apps/course/templates/course/inclusion/category_items.html b/apps/course/templates/course/inclusion/category_items.html index 5e6aeef5..66fb771b 100644 --- a/apps/course/templates/course/inclusion/category_items.html +++ b/apps/course/templates/course/inclusion/category_items.html @@ -1,5 +1,6 @@ {% for cat in category_items %} -
+
{{ cat.title }}
{% endfor %} \ No newline at end of file diff --git a/apps/course/views.py b/apps/course/views.py index 3ecd6bd0..ffbbee66 100644 --- a/apps/course/views.py +++ b/apps/course/views.py @@ -283,6 +283,15 @@ class CoursesView(ListView): context = super().get_context_data() filtered = CourseFilter(self.request.GET) context.update(filtered.data) + context['ages'] = Course.AGE_CHOICES[1:] + # context['age'] = list(map(int, context.get('age', []))) + age = context.get('age') + if age and age[0]: + age = int(age[0]) + context['age'] = [age] + context['age_name'] = dict(Course.AGE_CHOICES).get(age, '') + else: + context['age_name'] = '' return context def get_template_names(self): diff --git a/project/templates/lilcity/index.html b/project/templates/lilcity/index.html index 5d7b9d2d..c7b9d5b7 100644 --- a/project/templates/lilcity/index.html +++ b/project/templates/lilcity/index.html @@ -130,6 +130,13 @@ {% include "templates/blocks/popup_course_lock.html" %} {% include "templates/blocks/popup_subscribe.html" %}
+