1👍
✅
You’re looking for order_by
: Sort the queryset by descending ‘level’ and then get the first item by doing queryset[0]
.
I think your code should look like
r = Region.objects.get_location_name(user.location).order_by('-level')[0]
Source:stackexchange.com