Enable a PluginTemplateExtension subclass to register for multiple models #9904

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

Originally created by @jeremystretch on GitHub (Jun 25, 2024).

Originally assigned to: @jeremystretch on GitHub.

NetBox version

v4.0.6

Feature type

New functionality

Proposed functionality

A subclass of PluginTemplateExtension must currently register against a single model. For example:

from netbox.plugins import PluginTemplateExtension

class SiteCustomContent(PluginTemplateExtension):
    model = 'dcim.site'

This issue proposes adding an alternative models attribute to specify an iterable of models. For example:

from netbox.plugins import PluginTemplateExtension

class SiteCustomContent(PluginTemplateExtension):
    models = ['dcim.region', 'dcim.site', 'dcim.location']

The content introduced by this class will then be embedded on the relevant view for each of the listed models.

If models is defined, it will take precedence over model.

Use case

This obviates the need to create a redundant PluginTemplateExtension subclass for each core model.

Database changes

None

External dependencies

None

Originally created by @jeremystretch on GitHub (Jun 25, 2024). Originally assigned to: @jeremystretch on GitHub. ### NetBox version v4.0.6 ### Feature type New functionality ### Proposed functionality A subclass of [`PluginTemplateExtension`](https://netboxlabs.com/docs/netbox/en/stable/plugins/development/views/#extra-template-content) must currently register against a single model. For example: ```python from netbox.plugins import PluginTemplateExtension class SiteCustomContent(PluginTemplateExtension): model = 'dcim.site' ``` This issue proposes adding an alternative `models` attribute to specify an iterable of models. For example: ```python from netbox.plugins import PluginTemplateExtension class SiteCustomContent(PluginTemplateExtension): models = ['dcim.region', 'dcim.site', 'dcim.location'] ``` The content introduced by this class will then be embedded on the relevant view for each of the listed models. If `models` is defined, it will take precedence over `model`. ### Use case This obviates the need to create a redundant `PluginTemplateExtension` subclass for each core model. ### Database changes None ### External dependencies None
adam added the status: acceptedtype: featuretopic: plugins labels 2025-12-29 21:24:13 +01:00
adam closed this issue 2025-12-29 21:24:13 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#9904