I have the following query set:
max_latitude = Model.objects.aggregate(Max('latitude'))
When I print it, it returns {'latitude__max': 51.6639002} and not 51.6639002.
This is causing a problem when I want to add the latitudes together to calculate an average latitude.
If I do print(max_latitude.latitude) (field of Model object) I get the following: error:'dict' object has no attribute 'latitude'
How can I extract the actual number given from the queryset?
>Solution :
Point to the specific field name with
max_latitude = Model.objects.aggregate(Max('latitude'))['latitude__max']
You can also name your field as you want:
max_latitude = Model.objects.aggregate(latitude=Max('latitude'))