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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:27:43+00:00 2026-06-16T01:27:43+00:00

I have the following table structure: menu –{ page –{ title From the menu

  • 0

I have the following table structure:

menu --{ page --{ title

From the menu i would like to get fetch related pages. Pages also have related titles.
The following code works exactly as i would like however the for loop generates an individual query each iteration.

The prefetch_related in the initial query doesn’t seem to fetch the title. Is there a better way to do this resulting in a smaller number of queries?

 menu_data = MenuOrder.objects \
            .filter(menu__name=kwargs['menu']) \
            .filter(page__title_set__language=language) \
            .prefetch_related('page') \
            .order_by('priority')

    for menu_obj in menu_data:
        title_obj = menu_obj.page.title_set.get()

Thanks 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-16T01:27:45+00:00Added an answer on June 16, 2026 at 1:27 am

    Well, i found out that reversing the relationship has reduced the number of queries by a large number:

    title_data = Title.objects \
        .filter(language=language) \
        .filter(page__menuorder__menu__name=kwargs['menu']) \
        .order_by('page__menuorder__priority')
    

    I don’t know if there is a better method, so for now i will accept this one. Thanks to everyone that took a look..

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

Sidebar

Related Questions

I have a single-table with the following (relative) structure: foo_id, parent_foo_id, foo_name I would
I have the following table structure ZoneID int ZoneName varchar(50) I need to get
I have the following table structure: status: TINYINT locked_by: INTEGER date: DATETIME page: TINYINT
I have the following table structure in my aspx page. I need to place
I have following table structure, with many tables like this: data_1: +-------+--------+-------+ | views
I have a table structure like the following: table a: id int name varchar
I have the following table structure: ID | fname | lname | street |
I have the following table structure inside a view which gets displayed in the
I have the following table structure: ORGANIZATION_ID | Name | PARENT_ID -------------------------------------------------- 1 |
I have the following table structure (in MySQL): DocID, Code, IsDup, DopOf , where

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.