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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:43:48+00:00 2026-06-15T08:43:48+00:00

I am starting to use Django and while I have read the book and

  • 0

I am starting to use Django and while I have read the book and googled away I am afraid that I am not making the connection on some concepts to be able to resolve this.

I need to show several values corresponding to particular companies. The user first selects three companies to compare and then the response shows the data for those companies.

In my view, I create the querysets that I iterate in my template to show the data as follows:

VIEWS EXCERPT:

        C1 = form.cleaned_data['Company1']
        C2 = form.cleaned_data['Company2']
        C3 = form.cleaned_data['Company3']

        company_names = [C1,C2,C3]

        company1 = (Company_stats.objects.filter(period__exact=P, company_name__exact=C1))
        company2 = (Company_stats.objects.filter(period__exact=P, company_name__exact=C2))
        company3 = (Company_stats.objects.filter(period__exact=P, company_name__exact=C3))

        company_list = [company1,company2,company3]

TEMPLATE EXCERPT:

  {%for c in company_list%}    
     {%for z in c %}
        {{ z.company_name }}
        {{ z.nxt_m_ret_est }}    
        {{ z.nxt_m_ret_rat }}
     {% endfor %}  
  {% endfor %}

This works – however, as I have many more moving parts (I have simplified the view for the purpose of my question) it turns into an endless laundry list of querysets – I am 100% sure this is not DRY (in spite of the laundry reference 😉 Not to mention the length of the context.

I would really appreciate it if someone could help me learn to do this in the proper way. Thank you very much in advance!

  • 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-15T08:43:49+00:00Added an answer on June 15, 2026 at 8:43 am

    Try this:

    companies = ['Company1', 'Company2', 'Company3']
    
    company_names = [form.cleaned_data[c] for c in companies]
    
    company_list = Company_stats.objects.filter(
        period__exact=P, 
        company_name__in=company_names
    )
    

    Even if this doesn’t exactly fit your need, something similar should work.

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

Sidebar

Related Questions

I'm starting to learn Django through the use of Aymen Hourieh's Book. As I've
I'm starting to learn how to use Django on the Google App Engine. I
I am starting to use some Java code which was written by someone else.
i'm just starting to use asp.net mvc.. since i'm not familiar with it, i
I'm just starting to use Django for a personal project. What are the pros
I am just starting to use a web framework. I have decided I really
I have a Django project that uses Celery for running asynchronous tasks. I'm doing
Just starting to use Ruby on Rails to see what its like. I have
I have a couple special use cases for Django admin, and I'm curious about
I'm starting with webapp2. My english is not very good, so i'll use an

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.