S
S
s_katala2018-05-23 23:07:15
Django
s_katala, 2018-05-23 23:07:15

How to display posts on the page by order_by?

Friends, you need to display articles on the main page only if it has more, for example, 5 likes (likes are created),
that is, all articles get to the page fresh, but if the article gains, for example, 5 likes, it is duplicated on the main page! (NOT LIKE)
Now displayed by date

class Popular(generic.ListView):
  template_name = 'posts/popular.html'
  context_object_name = 'posts_list'
  def get_queryset(self):
    return Post.objects.filter(date_add__lte = timezone.now()).order_by('-date_add')

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
DrGeologist, 2018-05-24
@DrGeologist

In the view for the main

class ClassNameForPage(generic.ListView):
   ...
  def get_queryset(self):
    Post.objects.filter(date_add__lte = timezone.now(), like__gte = 5).order_by('-date_add')

But in fact I would like to see the model of the post and more about the likes.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question