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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:46:08+00:00 2026-06-03T09:46:08+00:00

I Am trying to refactor my code for a series of Django models, but

  • 0

I Am trying to refactor my code for a series of Django models, but this is valid for general python imports. Let me explain my setup and problem (with completly fake classes etc)

APP_ROOT/
|- __init__.py
|- tests/
|- urls.py
|- models/
|    |- __init__.py
|    |- BunchOfModels.py
|    |- SomeMoreModels.py
\- admin.py

in models.__init__:

# models/__init__.py
from APP_ROOT.models.BunchOfModels import *
from APP_ROOT.models.SomeMoreModels import *

this allows me to do the following:

from APP_ROOT.models import SuperModel
# Where SuperModel is in SomeMoreModels

The problem is that the class repr is:

<class 'project.APP_ROOT.models.SomeMoreModels.SuperModel'>
which messes up the foreign keys.

my question:

Is there a way to do this so that all my classes have a repr more like:
<class 'project.APP_ROOT.models.SuperModel'> without manually overloading the __repr__ for each class. I’m not even sure that this would solve the problem, and even if it did, This wouldn’t port very well.

or do i need to go back to using one big, ugly file…

  • 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-03T09:46:09+00:00Added an answer on June 3, 2026 at 9:46 am

    As I already commented, Django doesn’t recommend you to spread your models on several files. But this can solve your problem

    from django.db import models
    
    class SuperModel(models.Model):
        class Meta:
            app_label = 'APP_ROOT'
    

    app_label attr should be in Meta class inside every model. You also can inherit Meta from base metaclass.

    Other approach could be moving managers, utility function outside models.py (if you have them). But in this case you likely will get circular import.

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

Sidebar

Related Questions

I'm trying to refactor this code. I have this jquery ajax call $.ajax({ url:
I'm trying to refactor some python code and I'm stuck with an import error
I am trying to Refactor this code as it is repeated ad nauseum throughout
I am trying to refactor a piece of code which seems easily refactorable but
I'm trying to refactor some python code which I'm using for financial analytics processing
I'm trying to refactor this unsafe code to copy a single ARGB channel from
trying to refactor code to provide clean association A GAME has a HOME_TEAM and
I am trying to refactor some delphi 7 code. One of the procedures I'd
I have the following code for adding to/extracting from Zip. I'm trying to refactor
I am trying to refactor some code in an ASP.Net website and having a

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.