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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:38:25+00:00 2026-06-10T01:38:25+00:00

Hi Stackoverflow people, I am experiencing a strange issue with a select_related query in

  • 0

Hi Stackoverflow people,

I am experiencing a strange issue with a select_related query in Django. I have installed the django-cities app, which lists geo information for a large number of cities.
In my project model, I have created a foreignkey to the city element to store the location in my models.py.

from cities.models import City 
class Project(models.Model): 
   ...
   city = models.ForeignKey(City, blank = True, null = True)

Due to the large number of possible cities, I have created a query in my class based view which selects the related city field when creating a Project object.

from django.views.generic.edit import CreateView, UpdateView, DeleteView
from project.models import Project
class ProjectCreate(CreateView):
    queryset = Project.objects.select_related('city__country', 'city__region').all()
    template_name = 'solution/solution_create_form.html'

However, when I request the ProjectCreate class, Django still pulls an endless number of foreignkeys from the database. The logger is showing an unlimited number of the following requests.

…
DEBUG (0.000) SELECT “cities_region”.”id”, “cities_region”.”name”,
“cities_region”.”slug”, “cities_region”.”name_std”,
“cities_region”.”code”, “cities_region”.”country_id” FROM
“cities_region” WHERE “cities_region”.”id” = 3861887 ; args=(3861887,)
DEBUG (0.000) SELECT “cities_country”.”id”, “cities_country”.”name”,
“cities_country”.”slug”, “cities_country”.”code”,
“cities_country”.”population”, “cities_country”.”continent”,
“cities_country”.”tld” FROM “cities_country” WHERE
“cities_country”.”id” = 3865483 ; args=(3865483,) D
…

How can I force the select related method when I execute the ProjectCreate class?

Thank you for your help and 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-06-10T01:38:27+00:00Added an answer on June 10, 2026 at 1:38 am

    Without any testing, have you tried overriding the get_queryset method instead of using the queryset attribute? At least you will be more flexible with exception catching and other techniques.

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

Sidebar

Related Questions

Hi Stackoverflow people, I am confused with m2m queries in Django. I have a
Hello stackoverflow people! I've got a problem which I haven't been able to solve
Hello again Stackoverflow people! Assume I have these words: smartphones, smartphone I want to
Hi people stackoverflow. I'm working with MVVM, I have ViewModel call UserViewModel with a
Hello people of StackOverflow! I have used the searrch option, I've found some related
Hello people of stackoverflow. I have a problem. I'm trying to set up my
Hi Stackoverflow people, I am working on an organisation registration, in which orgs can
Hi Stackoverflow people, In the past, I always developed my Django projects locally with
There are plenty of questions on stackoverflow from people who have attempted to create
Hello great people of stackoverflow.com, I have a stumbled upon a great difficulty in

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.