Answer the question
In order to leave comments, you need to log in
Django queryset: how to get last 3 rows of result?
Article.objects.filter(date__date=today).order_by('date')[:3]
returns the first 3 rows sorted by date ascending .Article.objects.filter(date__date=today).order_by('-date')[:3]
returns the last 3 rows sorted by date descending .Article.objects.filter(date__date=today).order_by('-date')[:3]
Article.reverse()
returns an error. Article.objects.filter(date__date=today).order_by('date')[последние 3 строки]
Answer the question
In order to leave comments, you need to log in
Decision:
articles = list(Article.objects.filter(date__date=today).order_by('-date')[:3])
articles.reverse()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question