I have a model that where each entry has a date. How do I use queryset to find the entry with the earliest date? This is not dependent on 'pk' because I could add a row with an earlier date at a later time.
This is what I have so far and it doesn't seem to work:
Model.objects.get(min(date))
Thanks.
Model.objects.earliest('date')
earliest = Model.objects.order_by('date')[0]
You need to handle the case where there's no objects in Model
though.
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