I have a model with some fields as shown below
class Choclate(models.Model): name = models.CharField(max_length=256) price = models.IntegerField()
So, I want to get the name of the field with the lowest price value, so to get the lowest price value, we can do, as shown below, using Aggregations
from django.db.models import Avg, Max, Min choclates = Choclate.objects.all() lowest_price = choclates.aggregate(Min('price'))
So how to get the field name associated with the lowest price in django?
python django min django-aggregation
shiva krishna
source share