Reputation: 3400
I am doing the fat models approach, so I have transformed my models.py into a package thus:
+--polls/
| +--models/
| +--__init__.py
| +--__shared_imports.py
| +--Choice.py
| +--Question.py
My main part of the question is the __shared_imports.py
: I realized that we've common import statements in various modules in the package and decided to to have that file to do the imports, then in my modules I write this:
from __shared_imports.py import *
Everything works fine, but just want to know if this approach is good. I'll appreciate your thoughts on this.
Upvotes: 0
Views: 116
Reputation: 1797
avoid import *
because it will prevent tools like pyflakes from determining undefined variables.
to move all of it in a subdirectory and splitting it into separate files is not a bad idea, albeit mostly not needed. when your models.py file gets big, you should rather be thinking about splitting the project up into smaller apps.
Upvotes: 1
Reputation: 137
Got it.
In this case you need to import everything in __init__.py
.
Then you can export all names as __all__ = ['Choice', 'Question']
So, it will be enough just to import models package.
Example: __ init __.py
import Choice
import Question
__all__ = ['Choice', 'Question']
Upvotes: 2