Add custom toolbar toolbar to xadmin list page

Implemented through the Plugin of xadmin, in adminx.py

 

 

class Link2AdminPlugin(BaseAdminPlugin):
    link_2_admin = False

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

    #my_top_toolbar is the view_block block that exists in xadmin model_list.html
    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)

 

 

You can simply rewrite the code in xadmin model_list.html to insert anywhere on the list page, such as adding in model_list.html

 

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

 

 

The block_my_top_toolbar method adds a form form on the nodes to implement some data submission, and the get or post method in the admin class receives the form submission and processes the business logic.

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326907849&siteId=291194637