I have a simple class:
class BlogPost(models.Model):
title = models.CharField(max_length=150)
...
timestamp = models.DateTimeField()
How can I get the last five items from the database?
I tried to do this:
posts = BlogPost.objects.<any code>
BlogPost.objects.order_by('-timestamp')[:5]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With