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 7961219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:58:30+00:00 2026-06-04T04:58:30+00:00

I need some help with my problem. I have created a list of all

  • 0

I need some help with my problem. I have created a list of all my investments but now I need to seperate them by financial institution. I am trying to print a report out that will have all the investments for each financial institution on a seperate page but I am having trouble splitting them up.

For example what I want is:

TD Bank
– all investments for TD from my query

  • next page –

Scotia Bank
-all investments for Scotia from my query

etc

The following is my views.py that has the query and adding all the information to my list.

Can anyone help me find a way to split it up so I can have them seperated by financial institution?

def confirmations_report(request, *args, **kwargs):
from investments.models import Investment, InvestmentManager
from reports.forms import ConfirmationsForm
import ho.pisa as pisa
import cStringIO as StringIO
import os.path
confirm_letter_list = []
context = {}

if request.POST:
    form = ConfirmationsForm(request.POST)
    if form.is_valid():
        start_date = form.cleaned_data['start_date']
        end_date = form.cleaned_data['end_date']
        investments = Investment.objects.all().filter(contract_no = "",maturity_date__range=(start_date, end_date)).order_by('financial_institution')
        for i in investments:
            confirm_letter_list.append({
                'fi':i.financial_institution,
                'fi_address1': i.financial_institution.address1,
                'fi_address2': i.financial_institution.address2,
                'fi_city': i.financial_institution.city,
                'fi_prov': i.financial_institution.state_prov,
                'fi_country': i.financial_institution.country,
                'fi_postal': i.financial_institution.postal,
                'primary_owner': i.plan.get_primary_owner().member,
                'sin': i.plan.get_primary_owner().member.client.sin,
                'type': i.product.code,
                'purchase_amount': i.amount,
                'purchase_date': i.start_date,
            })
            context['confirmlist'] = confirm_letter_list
        context['inv'] = investments
    if request.POST.has_key('print_report_submit'):
        context['show_report'] = True
        context['mb_logo'] = os.path.join(os.path.dirname(__file__), "../../../media/images/mb_logo.jpg")
        html = render_to_string('reports/admin/confirm_report_print.html', RequestContext(request,context))
        result = StringIO.StringIO()
        pdf = pisa.pisaDocument(StringIO.StringIO(html.encode("ISO-8859-1")), result)
        response = HttpResponse(result.getvalue(), mimetype='application/pdf')
        response['Content-Disposition'] = 'attachment; filename=unreceived-confirmations.pdf'
        return response

else:
    form = ConfirmationsForm()

context['form'] = form
return render_to_response('reports/admin/confirm_report.html', RequestContext(request, context))
  • 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-06-04T04:58:31+00:00Added an answer on June 4, 2026 at 4:58 am

    Use a defaultdict with a list.

    from collections import defaultdict
    my_list = defaultdict(list)
    for i in investments:
       my_list[i.financial_institution].append({ ... })
    

    Here is how you would use it:

    {% for i in my_list.iteritems %}
       Institution : {{ i.0 }}
       {% for z in i|slice:"1:" %}
         Total Items for {{ i.0 }} : {{ z|length }}
         {% for d in z }}
            {{ d.fi_address1 }}
            ....
         {% endfor %}
       {% endfor %}
    {% endfor %}
    

    Here is a simplified example:

    >>> from collections import defaultdict
    >>> d = defaultdict(list)
    >>> d['hello'].append({1:'One', 2:'Two'})
    >>> for i in d.iteritems():
    ...    print i[0]
    ...    for z in i[1:]:
    ...     print z
    ... 
    hello
    [{1: 'One', 2: 'Two'}]
    

    As you can see the inner loop contains the list of dicts that you have added, so you need to adjust your loop logic accordingly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need some help in solving this problem. We have a large amount of
i have a litte problem and i need some help :) For example i
I need some help to store some data efficiently. I have a large list
Need some help with this problem in implementing with XSLT, I had already implemented
Well i need some help here i don't know how to solve this problem.
i got some problem and need help .. my plan : 1. get ip
Need some help, please. I have a line of horizontal thumbnails loaded as ONE
Need some help to solve this. I have a gridview and inside the gridview
Need some help from javascript gurus. I have one page where http://www.google.com/finance/converter is embedded
Ok, here's the problem: I have a list of contacts, which i have created

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.