xadmin列表页添加自定义工具栏toolbar

通过xadmin的Plugin实现,adminx.py中

 

 

class Link2AdminPlugin(BaseAdminPlugin):
    link_2_admin = False

    def init_request(self, *args, **kwargs):
        return bool(self.link_2_admin)

    #my_top_toolbar为xadmin model_list.html中存在的view_block区块
    def block_my_top_toolbar(self, context, nodes):
       nodes.append(loader.render_to_string('product/blocks/my_top_toolbar.link_2_admin.html', context_instance=context))

xadmin.site.register_plugin(Link2AdminPlugin, ListAdminView)

 

 

可以简单改写xadmin model_list.html中的代码,实现插入列表页任意地方,如model_list.html中加入

 

<div class="btn-toolbar pull-right" role="toolbar" aria-label="...">
    {% view_block 'my_top_toolbar' %}&nbsp;&nbsp;
  </div>

 

 

block_my_top_toolbar方法在nodes上增加一个form表单,实现一些数据的提交,admin类中的get或post方法接收表单提交并处理业务逻辑。

 

posted @ 2017-02-07 12:10  大棚  阅读(1080)  评论(0)    收藏  举报