project
|
├ __init__.py
├ apps.py
├ models.py
├ routes.py
├ views.py
First, specify the class that represents the function list in models.py.
from django.db import models
from django.db.models.signals import post_save
class FuncList:
func_id = models.CharField(max_length=50)
callback = models.CharField(max_length=50)
def get_func_id(self):
return self.func_id
def set_func_id(self, func_id):
self.func_id = func_id
self.save()
def get_callback(self):
return self.callback
def set_callback(self, callback):
self.callback = callback
self.save()
# Save to DB
def save_function(**kwargs):
func_list = FuncList()
func_list.set_func_id(kwargs['func_id'])
func_list.set_callback(kwargs['callback'])
return
# Dynamic execution
def dynamic_execution(arg1, arg2):
# Function that executes the function read from DB
def execution_handler(func, **kwargs):
return func(**kwargs)
#Get function list from DB
func_list = FuncList.objects.all()
for i in range(len(func_list)):
# Execute the acquired functions in order
result = execution_handler(func=eval(func_list[i].callback),
arg1=arg1, arg2=arg2)
return result
I didn't have enough words, but thank you for coming to see it. Any questions in this article can be supplemented at the following sites. ~~ ・ ・ ・ Maybe ~~
Recommended Posts