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

  • Home
  • SEARCH
  • 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 6772779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:35:20+00:00 2026-05-26T15:35:20+00:00

I need to loop through my django list that I have passed to the

  • 0

I need to loop through my django list that I have passed to the template.

I have this code in my django view:

if plan:
    investments = Investment.objects.all().filter(plan = plan).order_by('maturity_date').filter(maturity_date__gte = now)
    for i in investments:
        financial_institution = i.financial_institution
        amount = i.get_current_value(date)
        fi_list.append({
            'fi': financial_institution,
            'amt':amount
        })
    context['list'] = fi_list

Which outputs:

[<financial_institution: Example> <amount: 5000>]

Now what I want to do is loop through this list, and if my javascript variable matches the item in the list, do further code. However I am stuck on how to do this.

Here is my javascript so far, using jQuery:

function cdic_limit(amount) {
        var limit = 100000.00;
        var list ="{{ list }}";
        var fi = $("#id_financial_institution option:selected").text();

    }

Down the road, what I ultimately want, is if the selected institution is in the list, check and make sure their total amount isn’t exceeding $100k

Any suggestions?

  • 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-26T15:35:21+00:00Added an answer on May 26, 2026 at 3:35 pm

    I don’t know what you intend to do with the fi_list variable that you add to the context. If you plan to list the institutions and their limits in a systematic way, such as a table, then it should be simple enough to retrieve the amount data in much the same way as you retrieved the selected financial institution’s name.

    If you intend to reveal to the user the amounts for all the institutions (which I don’t think you do), and by reveal I mean it exists anywhere in the HTML code, whether or not the browser renders it, then one thing you can do is encode fi_list into a JSON string, make your response have (in a script tag) code like:

    var finInst = jQuery.parseJSON( "{{ jsonString }}" );
    
    function checkLimit(amount) {
        // I don't know what amount is supposed to do.
        if (finInst[jQuery(this).text()] > 100000)
            // do amount > 100000 code
        else
            // amount within limit
    }
    

    With django/python code like:

    import json
    if plan:
        investments = Investment.objects.all().filter(plan = plan).order_by('maturity_date').filter(maturity_date__gte = now)
        fi_list = {}
        for i in investments:
            financial_institution = i.financial_institution
            amount = i.get_current_value(date)
            fi_list[financial_institution] = amount
        context['jsonString'] = json.dumps(fi_list)
    

    And finally, whenever an institution option is selected from the web page, trigger the checkLimit function.

    Honestly, this is really bad code because I think you don’t want to expose all these amount values for each institution (critically confidential info maybe?). So the only reliable way to produce on the fly results would be to use AJAX to call a django view whenever an institution is selected. You might want to look at dajaxproject to simplify these requests.

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

Sidebar

Related Questions

I have a list of richTextFormat documents that I need to loop through and
i have the following code ..i need to loop through end of the file
I have lot of png sequences that I need to loop through and display
I have a multi-dimensional array that I need to loop through and create <td></td>
I have a list of words, in Python I need to loop through each
ok so i have this array and i need to loop through <?php foreach($classes
A friend was in need of an algorithm that would let him loop through
I need to write some code that would loop though all rows of a
I have a number rather large, complex xml documents that I need to loop
I need to loop through the properties of a custom object type that I'm

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.