Answer the question
In order to leave comments, you need to log in
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
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')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question