diff --git a/apps/content/models.py b/apps/content/models.py index 5d93a2d7..57f744b5 100644 --- a/apps/content/models.py +++ b/apps/content/models.py @@ -3,6 +3,7 @@ from urllib.parse import urlparse from django.conf import settings from django.db import models from django.contrib.auth import get_user_model +from django.db.models.expressions import RawSQL from django.urls import reverse_lazy from django.utils import timezone from django.contrib.postgres.fields import ArrayField @@ -144,6 +145,7 @@ class GalleryImage(models.Model): class Banner(models.Model): PAGE_INDEX = 1 PAGE_COURSES = 2 + PAGE_SCHOOL = 3 text = models.TextField() button_text = models.CharField(max_length=50) @@ -164,6 +166,12 @@ class Banner(models.Model): verbose_name_plural = 'Банеры' ordering = ('-created_at',) + @classmethod + def get_for_page(cls, page): + return Banner.objects.filter(use=True, pages__contains=[page]).annotate( + is_main=RawSQL('main_banner @> %s', ([page],)) + ).order_by('-is_main') + class Contest(models.Model): title = models.CharField(max_length=255) diff --git a/apps/course/templates/course/courses.html b/apps/course/templates/course/courses.html index 64720f65..10a16ff9 100644 --- a/apps/course/templates/course/courses.html +++ b/apps/course/templates/course/courses.html @@ -4,12 +4,13 @@ {% block ogimage %}http://{{request.META.HTTP_HOST}}{% static 'img/og_courses.jpg' %}{% endblock ogimage %} {% block content %} - {% include "templates/blocks/banners.html" %} + {% if not banners|length %}
Вы житель мегаполиса и у вас нет времени дополнительно развивать своего ребенка? @@ -12,38 +10,3 @@