Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6738485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:22:28+00:00 2026-05-26T11:22:28+00:00

I am processing a queryset in a view to get a summary of data

  • 0

I am processing a queryset in a view to get a summary of data and need to be able to iterate over the resultant dataset in my template. I did this OK with a key and single value by building a dictionary and then using .items to work over key value pairs using:

{% for id,total in list_summary.items %}
    <tr class="{% cycle 'row1' 'row2' %}" >
        <td>{{id}}</td>
        <td>{{total}}</td>
    </tr>
{% endfor %}

The problem I have is that I need more than just a key and value. I need multiple values. I tried building a dictionary using a dictionary as the value but in the template I can’t get to the values in the dictionary.

What is the appropriate datastructure to build to make this work? I thought of a temporary model or making a custom template tag to access the sub dictionary values but I think there must be a better way to process queryset data prior to feeding it to a view.

My view code is here:

lists=lists.objects.filter(user_id=user_id)
list_summary={}
# make a dictionary that we wil iterate over in template. The dictionary has the total spend for each deal 
for list in lists:
    id       = list.id
    name     = list.deal_name
    price    = list.normal_price
    quantity = list.quantity
    total    = price * quantity
    try:
        list_item=list_summary[id]
        old_total=list_item['total']
        list_summary[id]={'name':name, 'total':old_total + total}
    except:
        list_summary[id]={'name':name, 'total':total}
context = {
           'list_summary':list_summary,
        }
return render_to_response("lists.html", context)

Any help would be much appreciated!

Many thanks in advance

Rich

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T11:22:29+00:00Added an answer on May 26, 2026 at 11:22 am

    I tried building a dictionary using a dictionary as the value but in
    the template I can’t get to the values in the dictionary.

    Why not? The values are also key/value pairs..

    {% for list_id, dict in list_summary.items %}
        list_id: {{ list_id }}
        {% for k, v in dict.items %}
            key: {{ k }} <!-- name, total -->
            value: {{ v }} 
        {% endfor }
    {% endfor %}
    
    
    {% for list_id, value in list_summary.items %}
        list_id: {{ list_id }}
        Name: {{ value.name }}
        Value: {{ value.value }
    {% endfor %}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In data processing, I frequently need to create a lookup data structure to map
I'm processing a bunch of tables using this program , but I need to
When processing a POST request in the Django views.py file, I sometimes need to
I am processing large amounts of data in iterations, each and iteration processes around
I have a data processing system that generates very large reports on the data
Which processing is fast Client-side or Server-side? for client side processing browser need to
While processing 500 MB data and trying to serialize it, GetStringForStringBuilder(String value, Int32 startIndex,
I am doing some processing on RGB and Depth data and constructing cloud points
after processing a upload file received from an external website, we need to send
I need to start processing a URL that will contain some emailand a GUID.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.