I am getting a json response back from an API call and converting to python list via json.loads()
. I am using Django’s {% regroup %}
to regroup and display by company, but the company_list
is ordered alphabetically. I would like to have the results grouped by company but the companies ordered by lowest price. Can anyone point me in the right direction? Thanks
results_list = [{“company”: “Adidas”, “price”: 100.0, }, {“company”: “Adidas”, “price”: 110.0, }, {“company”: “Brooks”, “price”: 80.0, }, {“company”: “Brooks”, “price”: 120.0, }, {“company”: “Nike”, “price”: 150.0, }, {“company”: “Nike”, “price”: 180.0, }, ]
desired_list = [{“company”: “Brooks”, “price”: 80.0, }, {“company”: “Brooks”, “price”: 120.0, }, {“company”: “Adidas”, “price”: 100.0, }, {“company”: “Adidas”, “price”: 110.0, }, {“company”: “Nike”, “price”: 150.0, }, {“company”: “Nike”, “price”: 180.0, }, ]
I am using this in the template to display the prices for each company.
{% regroup results_list by company as company_list %}
{% for company in company_list %}
{% include 'company_card.html' %}
{% endfor %}