Implement the ability to register arbitrary bulk actions for a model #11301

Closed
opened 2025-12-29 21:43:17 +01:00 by adam · 0 comments
Owner

Originally created by @jeremystretch on GitHub (Jun 20, 2025).

Originally assigned to: @jeremystretch on GitHub.

NetBox version

v4.3.2

Feature type

New functionality

Proposed functionality

Provide a mechanism for canonically declaring bulk action support for individual models. Currently, NetBox supports bulk edit and bulk delete functionality by default. Certain models, such as device components, support additional actions such as bulk renaming and bulk disconnecting. However, this is accomplished using customized templates in a nonstandard way.

We can implement a form of lightweight API to support arbitrary bulk operations for any model, obviating the need for customization in views and templates. This could be as simple as inheriting a base class:

class BulkEdit(BulkOperation):
    verb = _('Edit')
    button_class = 'warning'
    view_name = 'bulk_edit'

This class could be responsible for evaluating user permissions (based on the declared set of actions for a model), resolving the view, and rendering the UI button. Bulk operations could be declared under each generic view, with the ability to be overridden where needed:

class SiteListView(generic.ObjectListView):
    bulk_actions = (BulkEdit, BulkRename, BulkDelete)

It might also be feasible to extend view registration (register_model_view()) to automatically enable bulk operations.

Use case

This will unlock the implementation of bulk operations beyond the defaults (bulk edit & bulk delete) for more models.

Database changes

None

External dependencies

None

Originally created by @jeremystretch on GitHub (Jun 20, 2025). Originally assigned to: @jeremystretch on GitHub. ### NetBox version v4.3.2 ### Feature type New functionality ### Proposed functionality Provide a mechanism for canonically declaring bulk action support for individual models. Currently, NetBox supports bulk edit and bulk delete functionality by default. Certain models, such as device components, support additional actions such as bulk renaming and bulk disconnecting. However, this is accomplished using customized templates in a nonstandard way. We can implement a form of lightweight API to support arbitrary bulk operations for any model, obviating the need for customization in views and templates. This could be as simple as inheriting a base class: ```python class BulkEdit(BulkOperation): verb = _('Edit') button_class = 'warning' view_name = 'bulk_edit' ``` This class could be responsible for evaluating user permissions (based on the declared set of actions for a model), resolving the view, and rendering the UI button. Bulk operations could be declared under each generic view, with the ability to be overridden where needed: ``` class SiteListView(generic.ObjectListView): bulk_actions = (BulkEdit, BulkRename, BulkDelete) ``` It might also be feasible to extend view registration (`register_model_view()`) to automatically enable bulk operations. ### Use case This will unlock the implementation of bulk operations beyond the defaults (bulk edit & bulk delete) for more models. ### Database changes None ### External dependencies None
adam added the status: acceptedtype: featuretopic: pluginscomplexity: medium labels 2025-12-29 21:43:17 +01:00
adam closed this issue 2025-12-29 21:43:17 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#11301