Reputation: 13
I want to show all my blog in database and the lastest post to the order so I try
{%for i in post%}
{{post.title}}
{{post.post_time|date:"Y/m/d"}}
{{post.content}}
but I can't let the lastest one show on the top of the page
I know forloop.last can show lastest one but just did one time,
How to do with forloop ??
Upvotes: 0
Views: 104
Reputation: 3666
It looks like you have an ordering problem, try to order your result when you're querying, example: MyModel.objects.order_by('myfield')
uses -myfield
for descending order.
Upvotes: 2
Reputation: 11429
You have to do the ordering in your view.
# views.py
post = Post.objects.all().order_by('-post_time')
This will order your posts by date.
Upvotes: 1