Allow injection of form fields by plugins into standard models (and allow corresponding plugins to parse data on save) #9062

Open
opened 2025-12-29 20:44:58 +01:00 by adam · 5 comments
Owner

Originally created by @DanSheps on GitHub (Jan 8, 2024).

NetBox version

v3.7.0

Feature type

New functionality

Proposed functionality

Add a method to:

  • Allow plugins to inject form fields into a "core model" form (example: Interface)
    • Perhaps allow this to be done in a dynamic manner, such as only showing fields when certain properties are already selected, however this is not "core" to the proposal
  • Process the form field data and save via a "sub-form" save method (or whatever method is appropriate)

Use case

This would allow for extending of "core" models by plugins while not actually modifying the core model

As an example, lets say you want to the Interface model to collect more data regarding the layer 2 information (example, port security, spanning tree, etc). You would define the form and model in your plugin and tell it which form (or model) to hook into, it would then display the extra field in the corresponding model create/edit form. When saved, the form would validate both the parent form and the "sub-form" before saving.

Database changes

None required

External dependencies

None

Originally created by @DanSheps on GitHub (Jan 8, 2024). ### NetBox version v3.7.0 ### Feature type New functionality ### Proposed functionality Add a method to: * Allow plugins to inject form fields into a "core model" form (example: Interface) * Perhaps allow this to be done in a dynamic manner, such as only showing fields when certain properties are already selected, however this is not "core" to the proposal * Process the form field data and save via a "sub-form" save method (or whatever method is appropriate) ### Use case This would allow for extending of "core" models by plugins while not actually modifying the core model As an example, lets say you want to the Interface model to collect more data regarding the layer 2 information (example, port security, spanning tree, etc). You would define the form and model in your plugin and tell it which form (or model) to hook into, it would then display the extra field in the corresponding model create/edit form. When saved, the form would validate both the parent form and the "sub-form" before saving. ### Database changes None required ### External dependencies None
adam added the type: featurenetboxstatus: backlogcomplexity: high labels 2025-12-29 20:44:58 +01:00
Author
Owner

@abhi1693 commented on GitHub (Jan 8, 2024):

Seems duplicate of #11961

@abhi1693 commented on GitHub (Jan 8, 2024): Seems duplicate of #11961
Author
Owner

@DanSheps commented on GitHub (Jan 9, 2024):

It does appear to be a duplicate. However that one was more or less also replalcing forms and manipulating data in the core model. This would be more akin to custom fields.

This however was brought up in a maintainers meeting a few months back by me which is why I am bringing it here (just a little lax on getting stuff from my brain into github)

@DanSheps commented on GitHub (Jan 9, 2024): It does appear to be a duplicate. However that one was more or less also replalcing forms and manipulating data in the core model. This would be more akin to custom fields. This however was brought up in a maintainers meeting a few months back by me which is why I am bringing it here (just a little lax on getting stuff from my brain into github)
Author
Owner

@peteeckel commented on GitHub (Feb 6, 2024):

It may be a duplicate (I'd say so, it's pretty much the core of what I wanted to suggest with #11961), but things have changed since then as NetBox 3.7.0 saw the introduction of plugin-injected fields in standard models, so adding plugin-injected form fields is the logical next step.

I highly appreciate this new approach, as the functionality could make my life much easier in some places and also greatly improve user experience - Custom Fields can be a bit clumsy at times.

@peteeckel commented on GitHub (Feb 6, 2024): It may be a duplicate (I'd say so, it's pretty much the core of what I wanted to suggest with #11961), but things have changed since then as NetBox 3.7.0 saw the introduction of plugin-injected fields in standard models, so adding plugin-injected form fields is the logical next step. I highly appreciate this new approach, as the functionality could make my life much easier in some places and also greatly improve user experience - Custom Fields can be a bit clumsy at times.
Author
Owner

@github-actions[bot] commented on GitHub (May 15, 2024):

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. Do not attempt to circumvent this process by "bumping" the issue; doing so will result in its immediate closure and you may be barred from participating in any future discussions. Please see our contributing guide.

@github-actions[bot] commented on GitHub (May 15, 2024): This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. **Do not** attempt to circumvent this process by "bumping" the issue; doing so will result in its immediate closure and you may be barred from participating in any future discussions. Please see our [contributing guide](https://github.com/netbox-community/netbox/blob/develop/CONTRIBUTING.md).
Author
Owner

@alehaa commented on GitHub (Dec 21, 2025):

At the moment, I'm writing a plugin that uses multi-table inheritance on the Tenant model to make it somewhat polymorphic. Additionally, I'm using signals and middleware to redirect users to the inherited model if necessary.

I believe a similar approach could be beneficial for this issue. Instead of determining which inherited model to redirect to, NetBox core logic could utilize the same mechanism to search for potential child models and gather fields to display. Roughly something like this:

class CoreModelForm(NetBoxModelForm):
    def collect_extended_fields(self):
        for cls in self.model.__subclasses__():
            yield from cls.get_extra_fields()  # TODO: exclude fields from parent model

The child collector method could also return form fields conditionally.

@alehaa commented on GitHub (Dec 21, 2025): At the moment, I'm writing a plugin that uses multi-table inheritance on the `Tenant` model to make it somewhat polymorphic. Additionally, I'm using signals and middleware to redirect users to the inherited model if necessary. I believe a similar approach could be beneficial for this issue. Instead of determining which inherited model to redirect to, NetBox core logic could utilize the same mechanism to search for potential child models and gather fields to display. Roughly something like this: ```Python class CoreModelForm(NetBoxModelForm): def collect_extended_fields(self): for cls in self.model.__subclasses__(): yield from cls.get_extra_fields() # TODO: exclude fields from parent model ``` The child collector method could also return form fields conditionally.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#9062