so i'm trying load model dynamically such :
urls.py
url(r'^list_view/([\w-]+)$', generic_list.as_view()), here's generic_list class in views.py :
class generic_list(listview): import importlib module_name = 'models' class_name = ? module = __import__(module_name, globals(), locals(), class_name) model = getattr(module, class_name) template_name = 'django_test/generic_list.html' about security, later i'll allow classes white list.
so, can put in place of question mark in order class name url?
if want have model loaded dynamically, this:
class generic_list(listview): template_name = 'django_test/generic_list.html' @property def model(self): return # code returns actual model more information property. basically, understand method attribute of class. instead of having define attribute @ class level (meaning code evaluated when file imported django), make attribute, it's acting method, allowing add business logic.
Comments
Post a Comment