1👍
✅
According to the data example you provide the value associated to 'business_service'
is a list
, thus the TypeError
when your write:
sorted(business_serializer.data, key=lambda k: (k['business_service']['price']))
You need to access the OrderedDict
in the list returned by k['business_service']
before you can access the key 'price'
.
So this should work:
sorted(business_serializer.data, key=lambda k: (k['business_service'][0]['price']))
FYI: Both, django 1.11, as well as python 2.7 are critically outdated.
0👍
You can extend the default Object Manager of a model. Writing your Custom Object Manager you can modify the queryset returned by the query.
DOCS here: https://docs.djangoproject.com/en/3.1/topics/db/managers/
- [Answered ]-How can I get my image to display using django?
- [Answered ]-Arithimetic operation before aggregation
- [Answered ]-Django Stopping loop after x times within a template
Source:stackexchange.com