File tree Expand file tree Collapse file tree 3 files changed +13
-11
lines changed Expand file tree Collapse file tree 3 files changed +13
-11
lines changed Original file line number Diff line number Diff line change 33import os .path
44
55from backend .core .path_conf import BASE_PATH
6- from backend .utils .import_parse import get_model_object
6+ from backend .utils .import_parse import get_model_objects
77
88
99def get_app_models () -> list [type ]:
@@ -21,9 +21,9 @@ def get_app_models() -> list[type]:
2121
2222 for app in apps :
2323 module_path = f'backend.app.{ app } .model'
24- obj = get_model_object (module_path )
24+ obj = get_model_objects (module_path )
2525 if obj :
26- objs .append (obj )
26+ objs .extend (obj )
2727
2828 return objs
2929
Original file line number Diff line number Diff line change 2323from backend .core .path_conf import PLUGIN_DIR
2424from backend .database .redis import RedisCli , redis_client
2525from backend .utils ._await import run_await
26- from backend .utils .import_parse import get_model_object , import_module_cached
26+ from backend .utils .import_parse import get_model_objects , import_module_cached
2727
2828
2929class PluginConfigError (Exception ):
@@ -63,9 +63,9 @@ def get_plugin_models() -> list[type]:
6363
6464 for plugin in get_plugins ():
6565 module_path = f'backend.plugin.{ plugin } .model'
66- obj = get_model_object (module_path )
66+ obj = get_model_objects (module_path )
6767 if obj :
68- objs .append (obj )
68+ objs .extend (obj )
6969
7070 return objs
7171
Original file line number Diff line number Diff line change @@ -39,7 +39,7 @@ def dynamic_import_data_model(module_path: str) -> Type[T]:
3939 raise errors .ServerError (msg = '数据模型列动态解析失败,请联系系统超级管理员' )
4040
4141
42- def get_model_object (module_path : str ) -> type | None :
42+ def get_model_objects (module_path : str ) -> list [ type ] | None :
4343 """
4444 获取模型对象
4545
@@ -52,10 +52,12 @@ def get_model_object(module_path: str) -> type | None:
5252 log .warning (f'模块 { module_path } 中不包含模型对象' )
5353 return None
5454 except Exception as e :
55- raise RuntimeError (f'获取模块 { module_path } 模型对象失败:{ e } ' )
55+ raise e
56+
57+ classes = []
5658
5759 for name , obj in inspect .getmembers (module ):
58- if inspect .isclass (obj ):
59- return obj
60+ if inspect .isclass (obj ) and module_path in obj . __module__ :
61+ classes . append ( obj )
6062
61- return None
63+ return classes
You can’t perform that action at this time.
0 commit comments