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

  • Home
  • SEARCH
  • 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 6214549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:53:52+00:00 2026-05-24T06:53:52+00:00

Is there a way of listing all python modules directly underneath a specified model

  • 0

Is there a way of listing all python modules directly underneath a specified model in the hierarchy?

I’ve got a Django web-app that is slowly growing, and I’ve re-organised it based on this article:

http://paltman.com/2008/01/29/breaking-apart-models-in-django/

However, I’m trying to improve on his technique by making use of introspection in the module initialization file (__ init __.py) in order to auto-detect all instances of the Django model class in the subordinate jobs. I’ve got this sort of got this working, but it still needs a static list of modules in the tree above it to work.

In case people are interested, here’s what my solution looks like:

from django.db.models.base import ModelBase
from sys import modules

moduleList = ['TechTree', 'PilotAbilities']
__all__ = []

for moduleName in moduleList:
  fullyQualifiedModuleName = '%s.%s' % (__name__, moduleName)
  moduleObj = __import__(fullyQualifiedModuleName)

  __all__ += [item for item in dir(moduleObj) if isinstance(getattr(moduleObj, item), ModelBase)]
  • 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-24T06:53:53+00:00Added an answer on May 24, 2026 at 6:53 am

    Well, you can get os.path.dirname(parent.__file__), and then glob.glob() or os.walk() and look for other init.py files.

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

Sidebar

Related Questions

Is there a direct way of listing out all form errors in Django templates.
Is there any way of listing all tables and columns names using UNION or
Is there any known way of listing the WMI classes and their properties available
Is there a good scala-esque (I guess I mean functional) way of recursively listing
Is there some way to make boost::python control the Python GIL for every interaction
In the application there is a default report the user see's listing all the
I'm looking for a way of doing this without listing out all of the
Is there a way to get ALL valid resolutions for a given screen? I
Is there some way in PyQt to get a collection of all QLineEdit objects?
Is there an easy way to remove all non alphanumeric characters from a string

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.