0

I'm trying to convert the following queryset into a dictionary that I can then parse via a html template.

team | season | type | scope | rank | value
a    | 2018   | reg  | l5    | 5    | 0.118
a    | 2018   | reg  | l10   | 6    | 1.251
b    | 2018   | reg  | l5    | 20   | 0.005
b    | 2018   | reg  | l10   | 15   | 3.058
c    | 2018   | reg  | l5    | 35   | 0.785

The issue I'm running into is that I need all rows, and I can't filter down to the 1 instance I need. I need to be able to place the values in specific spots in my template.

I'd like to turn the query set into a dictionary, at which point I could just reference: team[a].season[2018].type[reg].scope[l5].rank and team[a].season[2018].type[reg].scope[l5].value. But I can't figure out how to do so.

Any help would be appreciated!

George Rodman
  • 289
  • 7
  • 19
  • 1
    What have you tried so far and what went wrong? – Selcuk Oct 12 '18 at 00:00
  • This has been answered here: https://stackoverflow.com/questions/7811556/how-do-i-convert-a-django-queryset-into-list-of-dicts – suavesav Oct 12 '18 at 00:10
  • 2
    Possible duplicate of [How do I convert a Django QuerySet into list of dicts?](https://stackoverflow.com/questions/7811556/how-do-i-convert-a-django-queryset-into-list-of-dicts) – Dmitry M Oct 12 '18 at 01:21
  • Thanks! This solves the first part of my problem. How would I then parse out a RANK and VALUE field, based on the other parameters in the dictionary? If I wanted to put one of the values in VALUE field in a HTML, what would the reference template look like? – George Rodman Oct 13 '18 at 03:15
  • Check out https://stackoverflow.com/a/62073213/9384511 – ABN Jun 10 '23 at 04:19

0 Answers0