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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:26:03+00:00 2026-06-12T19:26:03+00:00

Have a SQL problem, adding this model all works correctly, the problem is in

  • 0

Have a SQL problem, adding this model all works correctly, the problem is in ADMIN.

When I add the data just few to each table, by clicking on TYPE & PAGE in ADMIN the page is loading so slow, installed debug_toolbar and SQL took 17 seconds for the TYPE. When I tried the PAGE it gave me timeout, my question is what is wrong with my model? Is it constructed bad?

My goal is this lets say example:

http://www.example.com/audi/4doors/s4/sport/red/audi-url

Basically all 6 urls are dynamic that I would specify in the each table and would be in the PAGE as dropdowns also in others. What is the optimal way to do that or optimize the model?

Here is a screenshot of TYPE page loading:

screenshot: http://cl.ly/image/2931040E0t35

Please help thanks

from django.db import models

class Client(models.Model):
    title = models.CharField(max_length=100, unique=True)
    def __unicode__(self):
        return self.title

class Category(models.Model):
    client = models.ForeignKey(Client, to_field='title')
    title = models.CharField(max_length=200, unique=True)
    def __unicode__(self):
        return self.title

class Subcategory(models.Model):
    client = models.ForeignKey(Client, to_field='title')
    category = models.ForeignKey(Category, to_field='title')
    title = models.CharField(max_length=200, unique=True)
    def __unicode__(self):
        return self.title

class Project(models.Model):
    client = models.ForeignKey(Client, to_field='title')
    category = models.ForeignKey(Category, to_field='title')
    subcategory = models.ForeignKey(Subcategory, to_field='title')
    title = models.CharField(max_length=200, unique=True)
    def __unicode__(self):
        return self.title

class Type(models.Model):
    client = models.ForeignKey(Client, to_field='title')
    category = models.ForeignKey(Category, to_field='title')
    subcategory = models.ForeignKey(Subcategory, to_field='title')
    project = models.ForeignKey(Project, to_field='title')
    title = models.CharField(max_length=200, unique=True)
    def __unicode__(self):
        return self.title

class Page(models.Model):
    client = models.ForeignKey(Client, to_field='title')
    category = models.ForeignKey(Category, to_field='title')
    subcategory = models.ForeignKey(Subcategory, to_field='title')
    project = models.ForeignKey(Project, to_field='title')
    type = models.ForeignKey(Type, to_field='title')
    pageurl = models.CharField(max_length=200)

Also just found out when I remove Foreign Keys from admin.py from list_display, it works blazing fast:

class ClientAdmin(admin.ModelAdmin):
    list_display = ('title',)
    admin.site.register(Client, ClientAdmin)

class CategoryAdmin(admin.ModelAdmin):
    list_display = ('client', 'title',)
    admin.site.register(Category, CategoryAdmin)

class SubcategoryAdmin(admin.ModelAdmin):
    list_display = ('client', 'category', 'title', )
    admin.site.register(Subcategory, SubcategoryAdmin)

class ProjectAdmin(admin.ModelAdmin):
    list_display = ('client', 'category', 'subcategory', 'title', )
    admin.site.register(Project, ProjectAdmin)

class TypeAdmin(admin.ModelAdmin):
    list_display = ('client', 'title', )
    admin.site.register(Type, TypeAdmin)

class PageAdmin(admin.ModelAdmin):
    list_display = ('client', )
    admin.site.register(Page, PageAdmin)

FOREIGN KEYS cannot be in list_display? How to optimize them?

Update:

class Client(models.Model):
    title = models.CharField(max_length=100, unique=True, db_index=True)
    def __unicode__(self):
        return self.title

class Category(models.Model):
    client = models.ForeignKey(Client)
    title = models.CharField(max_length=200, unique=True)
    def __unicode__(self):
        return self.title

class Subcategory(models.Model):
    client = models.ForeignKey(Client)
    category = models.ForeignKey(Category)
    title = models.CharField(max_length=200, unique=True)
    def __unicode__(self):
        return self.title

class Project(models.Model):
    client = models.ForeignKey(Client)
    category = models.ForeignKey(Category)
    subcategory = models.ForeignKey(Subcategory)
    title = models.CharField(max_length=200, unique=True)
    def __unicode__(self):
        return self.title

class Type(models.Model):
    client = models.ForeignKey(Client)
    category = models.ForeignKey(Category)
    subcategory = models.ForeignKey(Subcategory)
    project = models.ForeignKey(Project)
    title = models.CharField(max_length=200, unique=True)
    def __unicode__(self):
        return self.title

class Page(models.Model):
    client = models.ForeignKey(Client)
    category = models.ForeignKey(Category)
    subcategory = models.ForeignKey(Subcategory)
    project = models.ForeignKey(Project)
    type = models.ForeignKey(Type)
    pageurl = models.CharField(max_length=200)

UPDATE 2

from django.db import models


class Client(models.Model):
    title = models.CharField(max_length=100, primary_key=True)
    def __unicode__(self):
        return self.title

class Category(models.Model):
    client = models.ForeignKey(Client)
    title = models.CharField(max_length=200, primary_key=True)
    def __unicode__(self):
        return self.title

class Subcategory(models.Model):
    client = models.ForeignKey(Client)
    category = models.ForeignKey(Category)
    title = models.CharField(max_length=200, primary_key=True)
    def __unicode__(self):
        return self.title

class Project(models.Model):
    client = models.ForeignKey(Client)
    category = models.ForeignKey(Category)
    subcategory = models.ForeignKey(Subcategory)
    title = models.CharField(max_length=200, primary_key=True)
    def __unicode__(self):
        return self.title

class Type(models.Model):
    client = models.ForeignKey(Client)
    category = models.ForeignKey(Category)
    subcategory = models.ForeignKey(Subcategory)
    project = models.ForeignKey(Project)
    title = models.CharField(max_length=200, primary_key=True)
    def __unicode__(self):
        return self.title

class Page(models.Model):
    client = models.ForeignKey(Client)
    category = models.ForeignKey(Category)
    subcategory = models.ForeignKey(Subcategory)
    project = models.ForeignKey(Project)
    type = models.ForeignKey(Type)
    pageurl = models.CharField(max_length=200)

UPDATE 3 – ADMIN.PY

class ClientAdmin(admin.ModelAdmin):

    list_display = ('title',)

admin.site.register(Client, ClientAdmin)

class CategoryAdmin(admin.ModelAdmin):

    list_display = ('client', 'title',)

admin.site.register(Category, CategoryAdmin)

class SubcategoryAdmin(admin.ModelAdmin):

    list_display = ('client', 'category', 'title', )

admin.site.register(Subcategory, SubcategoryAdmin)

class ProjectAdmin(admin.ModelAdmin):

        list_display = ('client', 'category', 'subcategory', 'title', )

admin.site.register(Project, ProjectAdmin)

class TypeAdmin(admin.ModelAdmin):

    list_display = ('client', 'category', 'subcategory', 'project', 'title', )

admin.site.register(Type, TypeAdmin)

class PageAdmin(admin.ModelAdmin):

   list_display = ('client', 'category', 'subcategory', 'project', 'type', 'pageurl', )

admin.site.register(Page, PageAdmin)
  • 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-12T19:26:05+00:00Added an answer on June 12, 2026 at 7:26 pm

    Instead of that you can use raw_id_fields option of django admin.

    admin.site.register(Client)
    
    class CategoryAdmin(admin.ModelAdmin):
    
        raw_id_fields = ('client',)
    
    admin.site.register(Category, CategoryAdmin)
    
    class SubcategoryAdmin(admin.ModelAdmin):
    
        raw_id_fields = ('client', 'category')
    
    admin.site.register(Subcategory, SubcategoryAdmin)
    
    class ProjectAdmin(admin.ModelAdmin):
    
        raw_id_fields = ('client', 'category', 'subcategory')
    
    admin.site.register(Project, ProjectAdmin)
    
    class TypeAdmin(admin.ModelAdmin):
    
        raw_id_fields = ('client', 'category', 'subcategory', 'project')
    
    admin.site.register(Type, TypeAdmin)
    
    class PageAdmin(admin.ModelAdmin):
    
        raw_id_fields = ('client', 'category', 'subcategory', 'project', 'type')
    
    admin.site.register(Page, PageAdmin)
    

    this is the old one
    this is new sql query

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

Sidebar

Related Questions

I have 5 tables in MySQL, but i believe this is a SQL problem
I'm a beginner at SQL and have this fairly easy conditional problem: Every installation
We have a giant SQL Server 2005 database (75GB) which basically is just data
In my C# program I have a big problem: I add an SQL server
I've have this strange problem when adding a column to an existing table. The
I have an interesting SQL problem that I need help with. Here is the
I have a complex SQL problem in MS SQL Server, and in drawing on
I have problem with SQL query. If given order contains items, witch does not
I have a problem with sql (maths). I have a total payable given to
i have a problem with sql query. I need to get list of users.

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.