From 794ac8483847bbda6c02b302c61dbfbe664f9459 Mon Sep 17 00:00:00 2001 From: Kuroshini Date: Thu, 19 Dec 2019 17:04:56 +0300 Subject: [PATCH] must of the week logic --- apps/news/models.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/apps/news/models.py b/apps/news/models.py index bd0f3abe..ab65ed88 100644 --- a/apps/news/models.py +++ b/apps/news/models.py @@ -3,6 +3,7 @@ import uuid from django.conf import settings from django.contrib.contenttypes import fields as generic +from django.contrib.contenttypes.models import ContentType from django.contrib.postgres.fields import HStoreField from django.db import models from django.db.models import Case, When @@ -10,6 +11,7 @@ from django.utils import timezone from django.utils.translation import gettext_lazy as _ from rest_framework.reverse import reverse +from main.models import Carousel from rating.models import Rating, ViewCount from utils.models import (BaseAttributes, TJSONField, TranslatedFieldsMixin, HasTagsMixin, ProjectBaseMixin, GalleryModelMixin, IntermediateGalleryModelMixin, @@ -253,7 +255,12 @@ class News(GalleryModelMixin, BaseAttributes, TranslatedFieldsMixin, HasTagsMixi @property def must_of_the_week(self) -> bool: """Detects whether current item in carousel""" - return False + kwargs = { + 'content_type': ContentType.objects.get_for_model(self), + 'object_id': self.pk, + 'country': self.country, + } + return Carousel.objects.filter(**kwargs).exists() @property def publication_datetime(self):