16 lines
476 B
Python
16 lines
476 B
Python
#db/models/__init__.py
|
|
|
|
import pkgutil
|
|
import importlib
|
|
from sqlalchemy.ext.declarative import declarative_base
|
|
Base = declarative_base()
|
|
package_name = "db.models"
|
|
|
|
table_models = []
|
|
for _, module_name, _ in pkgutil.iter_modules(__path__):
|
|
module = importlib.import_module(f"{package_name}.{module_name}")
|
|
if hasattr(module, module_name):
|
|
model = getattr(module, module_name)
|
|
if hasattr(model, "__tablename__"):
|
|
table_models.append(model)
|