django管理员从动作注册动态模型 [英] django admin registering dynamic model from action
问题描述
admin.site.register(MyModel)
这显然是罚款。现在我希望这个模型是由于用户操作而自动加载的:
def user_action_from_admin_panel(......) :
.....
admin.site.register(MyModel)
MyModel类在管理中显示为无链接的纯文本。
任何想法来解决这个问题?
动态创建的模型不会显示管理员,除非他们的
app_labels
匹配INSTALLED_APPS中列出的软件包
这是再次设计,不应该考虑到一个错误。
确保您在创建模型时添加 app_label
model = create_model('DynamicModel',app_label ='existing_app')
/ pre>
还重新加载你的url conf,以便新模型获取链接
<$ c $从django.utils.importlib导入import_module
重新加载(import_module(settings.ROOT_URLCONF))
资料来源: https://code.djangoproject.com/wiki / DynamicModels#Admininterface
I have strange problem. In admin.py I can say:
admin.site.register(MyModel)
and this is obviously fine. Now I want this model to be loaded automatically as an result of user action:
def user_action_from_admin_panel(......): ..... admin.site.register(MyModel)
MyModel class gets shows up in the admin as plain text without links. Any ideas to solve this?
解决方案models created dynamically will not show up in the admin unless their
app_labels
match up with packages listed in INSTALLED_APPSThis is again by design, and should not be considered a bug.
Make sure you are adding
app_label
while creating a modelmodel = create_model('DynamicModel', app_label='existing_app')
Also reload your url conf so that new model gets links
# after creating model from django.utils.importlib import import_module reload(import_module(settings.ROOT_URLCONF))
Source: https://code.djangoproject.com/wiki/DynamicModels#Admininterface
这篇关于django管理员从动作注册动态模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!