Admin Site
register(model_or_iterable,admin_class=,**options)[source]
register the Model that need to be managed, or register the OptionClass of the AdminView
Parameters:
model_or_iterable– 传入 model 或是指定的 ModelOptionClass
admin_class– 当 model_or_iterable 为 Model 时,该参数为 ModelAdmin;model_or_iterable 为 AdminView 时 ,该参数为 OptionClass
注册需要管理的Model, 或是注册某AdminView的OptionClass.
参数:
model_or_iteralbe: 传入model或AdminView
admin_class:当model_or_iterable是Model时,该参数为ModelAdmin;当model_or_iterable是AdminView时,该参数为OptionClass.
例子:参见xadmin/adminx.py中,
from models import UserSettings
from views import CommAdminView, BaseAdminView
class UserSettingsAdmin(object):
model_icon='fa fa-cog'
hidden_menu =True
class GlobalSetting(object):
#设置base_site.html的Title
site_title ='兰山小亭'
#设置base_site.html的Footer
site_footer ='By KeaiDuo'
#菜单设置
defget_site_menu(self):
pass
#20160627
class BaseSetting(object):
enable_themes =True
use_bootswatch =True
xadmin.site.register(UserSettings, UserSettingsAdmin)
xadmin.site.register(CommAdminView, GlobalSetting)
xadmin.site.register(BaseAdminView, BaseSetting)
Register的输出结果:
!!!!!!!!xadmin\sites.py register 1 triggered model_or_iterable is <class 'xadmin.models.UserSettings'>, admin_class is <class 'xadmin.adminx.UserSettingsAdmin'>
!!!!!!!!xadmin\sites.py register 2 triggered model is <class 'xadmin.models.UserSettings'>, model._meta is xadmin.usersettings , model._meta.app_label is xadmin , model._meta.model_name is usersettings
!!!!!!!!xadmin\sites.py register 3 done admin_class is <class 'xadmin.sites.xadminusersettingsAdmin'>
!!!!!!!!xadmin\sites.py register 1 triggered model_or_iterable is <class 'xadmin.views.base.CommAdminView'>, admin_class is <class 'xadmin.adminx.GlobalSetting'>
!!!!!!!!xadmin\sites.py register2 triggered admin class is <class 'xadmin.views.base.CommAdminView'>
!!!!!!!!xadmin\sites.py register3 done admin_view_class is <class 'xadmin.adminx.GlobalSetting'>
!!!!!!!!xadmin\sites.py register 1 triggered model_or_iterable is <class 'xadmin.views.base.BaseAdminView'>, admin_class is <class 'xadmin.adminx.BaseSetting'>
!!!!!!!!xadmin\sites.py register2 triggered admin class is <class 'xadmin.views.base.BaseAdminView'>
!!!!!!!!xadmin\sites.py register3 done admin_view_class is <class 'xadmin.adminx.BaseSetting'>
In the final,
register_modelview(path,admin_view_class,name)[source]
register the classes Model Base Admin View to the AdminSite(将Model Base Admin View类注册到AdminSite)
Parameters:
path– view对应的url路径
admin_view_class– 注册的 Model Base Admin View 类
name– view对应的url name, 要包含两个%%s, 分别会替换为 app_label和module_name
the registered Model Base Admin View in the AdminSite can be used to create AdminView for the registered Model which will contain the relevant Model information. Please check xadmin.views.base.ModelAdminView to see the details. For example:(注册Model Base Admin View可以为每一个在xadmin注册的Model生成一个Admin View,并且包含相关的Model信息。注册后,用户可以通过访问‘/%(app_label)s/%(module_name)s/123/test’访问到该View。 具体内容可以参看xadmin.views.base.ModelAdminView。)
after the registration, the view can be accessed by path ‘/%(app_label)s/%(module_name)s/123/test’
例子,参见xadmin/views/__init__.py中register_builtin_views,
site.register_modelview(r'^, ListAdminView,name='%s_%s_changelist')
结果:!!!!!!!!xadmin\ sites.py register_modelview triggered path is ^$ , admin_view_class is <class 'xadmin.views.list.ListAdminView'>, name is %s_%s_changelist
In the final,
register_view(path,admin_view_class,name)[source]
an independent admin page e.g. login page, introduction page, help page, ect can be created by registering the AdminView class to the AdminSite.(将Admin View类注册到AdminSite,一般用于创建独立的admin页面,例如登录,介绍页面,帮助页面等。关于Admin View具体内容可以参看xadmin.views.base.BaseAdminView。)
Parameters:
path– view对应的url路径
admin_view_class– 注册的 Admin View 类
name– view对应的url name
See xadmin.views.base.BaseAdminView to see the details about AdminView. For example:
after the registration, the users can access the view through the path of ‘/test_view/’(注册后,用户可以通过访问'/test_view/'访问到该view。)
例子,参见xadmin/views/__init__.py中register_builtin_views,
site.register_view(r'^, IndexView,name='index')
结果:!!!!!!!!xadmin\ sites.py register_view triggered path is ^$ , admin_view_class is <class 'xadmin.views.website.IndexView'>, name is index
In the final,
register_plugin(plugin_class,admin_view_class)[source]
register the Plugin class to the instance of AdminSite, the instance of corresponding plugin class which is bound to the current view class will be effective when any instance of the AdminView classes runs.(将Plugin类注册到AdminSite,当任何Admin View实例运行时当前view绑定的plugin会生效。)
Parameters:
plugin_class– view对应的url路径
admin_view_class– 该 plugin 绑定的 Admin View 类
please see xadmin.views.base.BaseAdminPlugin about the details of Admin Plugin. For example:(关于Admin Plugin具体内容参看xadmin.views.base.BaseAdminPlugin。)
after the registration, the plugin will be called when the get_context method of SomeAdminView is invoked.(注册后,只要运行SomeAdminView实例的get_context方法,就会调用该plugin。)
例子,参见xadmin/plugins/__init__.py中register_builtin_plugins - > xadmin/plugins/actions.py,
site.register_plugin(ActionPlugin, ListAdminView)
结果:!!!!!!!!xadmin\ sites.py register_plugin triggered plugin_class is <class 'xadmin.plugins.actions.ActionPlugin'>, admin_view_class is <class 'xadmin.views.list.ListAdminView'>
In the final,
get_view_class(view_class,option_class=None,**opts)[source]
the most core method of xadmin is used to create specific AdminViewClass that belongs to xadmin(xadmin中最核心的方法,用于创建xadmin特有的AdminViewClass。
there are two steps of creating AdminView class instance and dynamically generating the mix class.(创建AdminView class有两步,动态生成mix的类。)
use the registered OptionClass (see method register), the option_class parameter and the view_class to dynamically create the class instance(使用已经注册的OptionClass, 通过option_class和view_class参数动态生成类)
retrieve the corresponding plugins according to the view_class and its super classes, and create it as the ‘plugins’ properties of the AdminViewClass(根据view_class及其继承类找到相应的plugins,作为生成AdminViewClass的plugins属性)