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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:31:49+00:00 2026-05-31T17:31:49+00:00

In django I have to models A and B, B has FK reference to

  • 0

In django I have to models A and B, B has FK reference to A.
A2B is one-to-many

In my controller code I select list of A according some criteria and this list is transferred to a template to generate html page.

This template uses FOR to generate list: {% for a in list_of_a %}

The question is that with every “a” printed I have to print related Bs as well. With non django code it would be simple join.
But how can I implement this in django?

thanks

  • 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-31T17:31:50+00:00Added an answer on May 31, 2026 at 5:31 pm

    Your question is vague, but the gist of it seems to be that you want to avoid the 1*N queries generated when looping through your As.

    In Django 1.4, you can use the new prefetch_related, which will still generate an extra query, but just one instead of 1*N.

    Previous versions of Django have nothing similar, but there’s an app called django-batch-select that can be used to gain roughly equivalent functionality.

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

Sidebar

Related Questions

I have Django models setup in the following manner: model A has a one-to-many
I have two models in Django: groups and entries. Groups has a many-to-many field
Lets say I have some Django model that has a list of numbers as
I have 3 django models, where the first has a foreign key to the
Consider three django models: AA, BB and CC. AA has an M2M reference to
I have a database, financials that has models created in django. In addition, it
I have 2 models in my Django code: class ModelA(models.Model): name = models.CharField(max_length=255) description
My Django model has a field within which I want to have reference logic.
I have a django application which has one main table/model which references various 'lookup'
I have three Django models that exist in a hierarchy: Protocol -> has Test

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.