@@ -127,6 +127,17 @@ async def generate(self, *, pk: int) -> None:
127127 if not init_filepath .exists ():
128128 async with aiofiles .open (init_filepath , 'w' , encoding = 'utf-8' ) as f :
129129 await f .write (gen_template .init_content )
130+ if 'api' in str (code_folder ):
131+ # api __init__.py
132+ api_init_filepath = code_folder .parent .joinpath ('__init__.py' )
133+ if not api_init_filepath .exists ():
134+ async with aiofiles .open (api_init_filepath , 'w' , encoding = 'utf-8' ) as f :
135+ await f .write (gen_template .init_content )
136+ # app __init__.py
137+ app_init_filepath = api_init_filepath .parent .joinpath ('__init__.py' )
138+ if not app_init_filepath :
139+ async with aiofiles .open (app_init_filepath , 'w' , encoding = 'utf-8' ) as f :
140+ await f .write (gen_template .init_content )
130141 # 写入代码文件呢
131142 async with aiofiles .open (code_filepath , 'w' , encoding = 'utf-8' ) as f :
132143 await f .write (code )
@@ -161,6 +172,10 @@ async def download(self, *, pk: int) -> io.BytesIO:
161172 f'from backend.app.{ business .app_name } .model.{ business .table_name_en } '
162173 f'import { to_pascal (business .table_name_en )} \n ' ,
163174 )
175+ if 'api' in new_code_path :
176+ # api __init__.py
177+ api_init_filepath = os .path .join (* new_code_path .split ('/' )[:- 2 ], '__init__.py' )
178+ zf .writestr (api_init_filepath , gen_template .init_content )
164179 zf .close ()
165180 bio .seek (0 )
166181 return bio
0 commit comments