Last active
December 14, 2015 04:19
-
-
Save EyePulp/5027698 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# don't forget each model needs | |
# class Meta: | |
# app_label = 'app_name' # or whatever the app name is | |
PACKAGE = 'project_name.app_name.models' # <--- SET YOUR PACKAGE NAME | |
import os | |
import types | |
module_methods = [] | |
model_dir = os.path.dirname(__file__) | |
for name in os.listdir(model_dir): # Search through every file inside this directory. | |
if os.path.isfile(os.path.join(model_dir,name)) and name.lower().endswith('.py') and name != "__init__.py": | |
mname = name.rpartition('.')[0] | |
module = __import__('%s.%s' % (PACKAGE, mname),{}, {},mname) # Import the module file | |
for method in dir(module): # find all clases inside it. | |
item = getattr(module, method) | |
if isinstance(item, (type, types.ClassType)): | |
exec "%s = item" % method # Found a class, bring into the module namespace. | |
module_methods.append(method) | |
__all__ = module_methods # Hide everything other than the classes from other modules. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment