python - Django using aggregate MAX -
i have following...
r = region.objects.get_location_name(user.location)
which returns:
[<region: great britain>, <region: europe>]
next want return object max highest parent
.
i have tried this:
r = region.objects.get_location_name(user.location).aggregate(max('level'))
but not return object returns...
{'level__max': 1}
why?
you're looking order_by
: sort queryset descending 'level' , first item doing queryset[0]
.
i think code should like
r = region.objects.get_location_name(user.location).order_by('-level')[0]
Comments
Post a Comment