posts sorted by public date or event start depend on post type

This commit is contained in:
2021-04-13 09:45:13 +00:00
parent 9a1b1a0884
commit bac25e25c7
4 changed files with 29 additions and 3 deletions

View File

@@ -12,6 +12,19 @@ class PostManager(models.Manager):
def get_visible_articles(self):
return self.get_queryset().filter(is_hidden=False)
def get_date_sorted_list(self):
post_list = []
for post in self.get_visible_articles():
if post.post_type != "N":
post_list.append((post, post.event_start.date()))
else:
post_list.append((post, post.public_date))
result = sorted(post_list, key=lambda x: x[1], reverse=True)
posts = [x[0] for x in result]
return posts
def get_last_months_posts(self):
date_today = timezone.now().date()
return self.get_visible_articles().filter(
@@ -43,6 +56,19 @@ class ArticleManager(models.Manager):
def get_visible_articles(self):
return self.get_queryset().filter(is_hidden=False)
def get_date_sorted_list(self):
post_list = []
for post in self.get_visible_articles():
if post.post_type != "N":
post_list.append((post, post.event_start.date()))
else:
post_list.append((post, post.public_date))
result = sorted(post_list, key=lambda x: x[1], reverse=True)
posts = [x[0] for x in result]
return posts
def get_pinned_article(self):
return self.get_visible_articles().filter(is_pinned=True).first()