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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:35:05+00:00 2026-05-16T18:35:05+00:00

I am working with Django for a while and now that my tree and

  • 0

I am working with Django for a while and now that my “tree” and whole DB is filled with data (note: existing database), I was wondering if the “one model per table” is really better at this point than “one model per select”.

I have got one table – objtree. This is the place where I have all nodes (brands, categories, tags, etc.) stored. As you can imagine it is heavily used in my administration. Today I had to add another foreign key for another table, but I have already 2 Foreign keys there. The problem is that I use this model for almost everything, BUT the foreign keys are used rarely, not to mention the third one that would be used this one time. Since each of these tables have 20k+ (minimum) rows and the foreign keys are used rarely, I wonder if it wouldnt be better to use “one model class per select” – speed wise.

Would this approach affect the speed at all? So far it worked fine for me (model per table), but isnt that kind of an overkill for such large DB?

Any opinion is appreciated.

Regards

Edit:

Here is the model. The 3 foreign keys are needed rarely, but as it is now, they are selected anyway, even if I dont need them (maybe there is an easy way to specify which of them I dont want to use when doing e.g. Model.objects.all()).

So the question is if it would be better to have lets say 3 models, where I would use the foreign keys respectively. Would that affect the speed? Or is bad approach? Maybe I am doing something wrong, I dont know.

class Objtree(models.Model):
  node_id = models.AutoField(
    primary_key = True
  )
  type_id = models.IntegerField()
  parent_id = models.IntegerField()
  sort_order = models.IntegerField(
    null = True, 
    blank = True
  )
  name = models.CharField(
    unique = True, 
    max_length = 255, 
    blank = True
  )
  lft = models.IntegerField()
  rgt = models.IntegerField()
  depth = models.IntegerField()
  added_on = models.DateTimeField()
  updated_on = models.DateTimeField()
  status = models.IntegerField()
  point_to = models.IntegerField(
    null = True, 
    blank = True
  )
  node = models.ForeignKey(
    'Objtree_labels', 
    verbose_name = 'Objtree_labels', 
    to_field = 'node_id'
  )
  specs = models.ForeignKey(
    'OptionSpecs', 
    verbose_name = 'OptionSpecs', 
    db_column = 'node_id', 
    null = True, 
    blank = True
  )
  ct = models.ForeignKey(
    'CategoryTemplate',
    verbose_name = 'CategoryTemplate',
    db_column = 'node_id',
    to_field = 'group_id',
    null = True,
    blank = True
  )
  • 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-16T18:35:06+00:00Added an answer on May 16, 2026 at 6:35 pm

    I was wondering if the “one model per table” is really better at this point than “one model per select”.

    What is “model per select”? It sounds like your model is wrong.

    The problem is that I use this model for almost everything, BUT the foreign keys are used rarely, not to mention the third one that would be used this one time.

    What are you doing? This sounds like you’re not doing the database modeling part of the job correctly. It sounds — from this quick description — like you’re throwing attributes at models in a haphazard way.

    There’s no sensible alternative to “model per table”. The questions you should be asking are “What am I modeling?” “What is this real-world object?” And “What is the relational database description of this thing?”


    if it would be better to have lets say 3 models, where I would use the foreign keys respectively?

    Three models means three copies of the tree structure, each with just one foreign key.

    The essential questions, however, still remain.

    • What is this? Are these three separate things? Are these three aspects of one thing? These are not technical questions, but reality questions. Don’t fret over performance. Fret over modeling reality with a great deal of fidelity.

    • ‘Objtree_labels’, ‘OptionSpecs’, ‘CategoryTemplate’ — what real-world objects are these? Labels — usually don’t exist in the real world. Option specs may be something tangible. A category template doesn’t sound like a real thing.

    Would that affect the speed?

    Never. One table with lots of foreign keys and three tables with one foreign key each will be largely indistinguishable in speed. Unless, of course, you are regularly having to match values between separate tables, then the “join” among separate tables will incur some cost.

    But if the three values are truly independent — three separate things — they must be in separate tables to reflect the fact that they are different kinds of things.

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

Sidebar

Related Questions

I am working on an django application that will return what historically was a
I am working through the examples in a Django book that I have, but
Am working with django Publisher example, I want to list all the publishers in
I'm working on a django app right and I'm using cherrypy as the server.
I just got done working through the Django tutorials for the second time, and
Hey, i am currently working on a django app for my studies, and came
I'm working on my first Django application. In short, what it needs to do
I'm working on a blog application in Django. Naturally, I have models set up
I'm working on a little django app for reserving prints of paintings. Customers go
I am working on a web application using Python (Django) and would like to

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.