0

I know it's possible to import everything in a file into another file like this:

from app1.models import * 

But I want to do something like this:

from *.models import *

It means import everything inside models file from any directory.

for example in this file structure

/module
    /app1
        /models.py
    /app2
        /models.py
    /allModels.py

I want to import all models.py files into allModels.py

Is it possible? Do we have such syntax?

Mmd M
  • 45
  • 1
  • 9
  • There is no such way – Minuddin Ahmed Rana Jun 06 '18 at 07:15
  • Django detects models inside app well-registered in `settings.INSTALLED_APPS`, by doing what you want, how Django will suppose to detect your models, also changes? why do you want to do that? – Lemayzeur Jun 06 '18 at 07:18
  • 3
    No, there isn't. Note, [starred imports are considered bad practice generally](https://stackoverflow.com/questions/2386714/why-is-import-bad?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa). It's good that what you are trying to do isn't allowed, because it would almost certainly be abused. – juanpa.arrivillaga Jun 06 '18 at 07:19
  • how about, reading the list of all .py files using os.listdir and use a loop to import them all? – Surya Tej Jun 06 '18 at 07:28

0 Answers0