Added support for post install scripts when a model is created
This commit is contained in:
parent
b678823a0e
commit
97ab25c162
2 changed files with 30 additions and 2 deletions
|
|
@ -50,8 +50,6 @@ def start():
|
|||
|
||||
args.model=args.model.replace('/', '.')[:-3] #.replace('.py', '')
|
||||
|
||||
|
||||
|
||||
try:
|
||||
|
||||
model=import_module(args.model)
|
||||
|
|
@ -308,6 +306,34 @@ def start():
|
|||
if not os.path.isfile(backup_path):
|
||||
create_backup(original_file_path, backup_path)
|
||||
|
||||
# Execute script
|
||||
|
||||
arr_script_model=args.model.split('.')
|
||||
|
||||
arr_script_model.pop()
|
||||
|
||||
script_model='.'.join(arr_script_model)+'.scripts.install'
|
||||
|
||||
script_py=script_model.replace('.', '/')+'.py'
|
||||
|
||||
if os.path.isfile(script_py):
|
||||
|
||||
locked_file='/'.join(arr_script_model)+'/scripts/locked'
|
||||
|
||||
if not os.path.isfile(locked_file):
|
||||
|
||||
script_install=import_module(script_model)
|
||||
|
||||
script_install.run()
|
||||
|
||||
f=open(locked_file, 'w')
|
||||
|
||||
f.write('OK')
|
||||
|
||||
f.close()
|
||||
|
||||
|
||||
#script_model=args.model+''
|
||||
|
||||
print(Style.BRIGHT+"All tasks finished")
|
||||
|
||||
|
|
|
|||
|
|
@ -310,6 +310,8 @@ class WebModel:
|
|||
|
||||
for extra_field in self.fields[field].select_fields:
|
||||
|
||||
# Check if extra_field is ForeignKeyField, if yes, call this function recursively.
|
||||
|
||||
extra_fields.append("`"+table_name+"`.`"+extra_field+"` as `"+table_name+"_"+extra_field+"`")
|
||||
else:
|
||||
# Add normal field to sql query
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue