done
This commit is contained in:
parent
962dc2f480
commit
755490c6cf
|
|
@ -5,7 +5,7 @@ from django.utils import timezone
|
|||
from django.utils.translation import gettext_lazy as _
|
||||
from rest_framework.reverse import reverse
|
||||
from utils.models import BaseAttributes, TJSONField, TranslatedFieldsMixin
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from random import sample as random_sample
|
||||
|
||||
|
||||
class NewsType(models.Model):
|
||||
|
|
@ -104,23 +104,18 @@ class News(BaseAttributes, TranslatedFieldsMixin):
|
|||
|
||||
@property
|
||||
def list_also_like_news(self):
|
||||
# news_content_type = ContentType.objects.get(app_label="news", model="news")
|
||||
|
||||
# tg_name = self.tags.filter(metadata__content_type=news_content_type)
|
||||
# without "distinct" method the doubles are arising
|
||||
like_news = News.objects.published().filter(news_type=self.news_type, tags__in=models.F("tags"))\
|
||||
.exclude(id=self.id).distinct()
|
||||
|
||||
# print(tg_name)
|
||||
news_count = like_news.count()
|
||||
|
||||
# tag_id = self.tags.all()
|
||||
news_content_type = ContentType.objects.get(app_label="news", model="news")
|
||||
#
|
||||
like_news = News.objects.filter(is_publish=True, news_type=self.news_type,
|
||||
tags__content_type=news_content_type)
|
||||
if news_count >= 6:
|
||||
random_ids = random_sample(range(news_count), 6)
|
||||
else:
|
||||
random_ids = random_sample(range(news_count), news_count)
|
||||
|
||||
#
|
||||
# print("LINE 112", like_news)
|
||||
|
||||
# news_list = [self.description, "extra", "field", "test", self.slug]
|
||||
|
||||
news_list = [{"id": n.id, "slug": n.slug} for n in like_news]
|
||||
news_list = [{"id": like_news[r].id, "slug": like_news[r].slug} for r in random_ids]
|
||||
|
||||
return news_list
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user