Reputation: 51261
es = Employee.objects.filter(a few filters).aggregate(Max('Age'))
That query is going to give me the oldest employee, so I also want to know some other information associated with that row, for example, the id.
How can I accomplish that? Thanks.
Upvotes: 0
Views: 559
Reputation: 4191
You do not need aggregate you only have to order by descending Ages your query set
Employee.objects.filter(a few filters).order_by(['-Age'])[0]
Will give you the oldest
Or if you have several old item
age = None
for x in Employee.objects.filter(a few filters).order_by(['-Age']):
if age and age != x.Age:
break
age = x.Age
Upvotes: 1