Get minimum value field name using aggregation in django
You can try below code to get exact thing you want
>>> from django.db.models import Min
>>> Choclate.objects.filter().values_list('name').annotate(Min('price')).order_by('price')[0]
(u'First1', 10)
>>>
First1
is the field name having price = 10
which is lowest value.
Documentation Link
If you pass the Min
as positional argument, then the field's name is price__min
. Otherwise, if you pass it as keyword argument, i.e. aggregate(my_min=Min('price'))
, then it will be available with the same name as the argument, in this case my_min
. Docs