[Solved]-How to get max value in django ORM

31👍

From the documentation:

>>> from django.db.models import Max
>>> AuthorizedEmail.objects.aggregate(Max('added'))

And to fetch the value in the template:

{{ item.added__max }}

9👍

latest returns the latest object in the table according to the added date:

AuthorizedEmail.objects.filter(group=group).latest('added')

5👍

AuthorizedEmail.objects.filter(group=group).order_by('-added')[0]

2👍

Leave a comment