[Answer]-Python — How to get Oldest date from a QuerySet?

1👍

You can annotate min datetime:

from django.db.models import Min
qs.values('title', 'title__name').annotate(count=Count('book'), min=Min('rx_datetime'))

It will give you something like:

[{'count': 3, 'title': 1, 'title__name': u'OliverTwist', 'min': datetime.datetime(2013,5,1,0,0,0)}]
👤iMom0

Leave a comment