Custom script: ObjectVar dropdown display field #9420

Closed
opened 2025-12-29 20:49:34 +01:00 by adam · 3 comments
Owner

Originally created by @steinzi on GitHub (Apr 1, 2024).

NetBox version

v3.7.4

Feature type

Change to existing functionality

Proposed functionality

[I know you'll have to reject this, but I just wanted this idea written down somewhere.]

I'm not 100% sure but, I think extending / modifying the 'ObjectVar' object (and since 'MultiObjectVar' inherits from ObjectVar, that would cover the 2 script Var types that need this feature)

Here's where i'm not sure at all how to mess with the serializer / deserializer or to override the str method to return self.description or whatever field I want to display....

But the ideal end functionality would be to have something like this a option "display_field" that could render out to the user another value besides the raw prefix value in this example.

    parent_prefix = ObjectVar(
        description="this is a prefix selection for you my dear network engineering friend!",
        model=Prefix,
        display_field="description",
    )

I'm going to go and try to figure out an "actionable implementation plan" and I'll resubmit this.

Use case

When you want to give the user info about their selection based on each object in the dropdown list,
example: Here I have two parent prefixes, but the network engineer has no idea what the difference is between them.
image

Solution: By being able to display the "description" value of the object instead of just the KEY value field in this case the "prefix", the user can make an informed choice and this let's the script be more dynamic and require less maintenance than if you just make a "ChoiceVar" that you need to painstakingly update by hand every time you add to the object pool using roles or tags or whatever.
image

Database changes

None

External dependencies

None?

Originally created by @steinzi on GitHub (Apr 1, 2024). ### NetBox version v3.7.4 ### Feature type Change to existing functionality ### Proposed functionality _[I know you'll have to reject this, but I just wanted this idea written down somewhere.]_ I'm not 100% sure but, I think extending / modifying the '[ObjectVar](https://github.com/netbox-community/netbox/blob/699dd7259761da0d70f1a1bf94b088d44090f56d/netbox/extras/scripts.py#L188C7-L188C16)' object (and since 'MultiObjectVar' inherits from ObjectVar, that would cover the 2 script Var types that need this feature) Here's where i'm not sure at all how to mess with the serializer / deserializer or to override the __str__ method to return self.description or whatever field I want to display.... But the ideal end functionality would be to have something like this a option "display_field" that could render out to the user another value besides the raw prefix value in this example. ```python parent_prefix = ObjectVar( description="this is a prefix selection for you my dear network engineering friend!", model=Prefix, display_field="description", ) ``` I'm going to go and try to figure out an "actionable implementation plan" and I'll resubmit this. ### Use case When you want to give the user info about their selection based on each object in the dropdown list, **example**: Here I have two parent prefixes, but the network engineer has no idea what the difference is between them. <img width="736" alt="image" src="https://github.com/netbox-community/netbox/assets/57838925/c38256d5-2261-4982-885d-d498a5c39e33"> **Solution**: By being able to display the "description" value of the object instead of just the KEY value field in this case the "prefix", the user can make an informed choice and this let's the script be more dynamic and require less maintenance than if you just make a "ChoiceVar" that you need to painstakingly update by hand every time you add to the object pool using roles or tags or whatever. <img width="602" alt="image" src="https://github.com/netbox-community/netbox/assets/57838925/022444de-82f7-46bf-bd33-a6cfc23a7042"> ### Database changes None ### External dependencies None?
adam added the type: feature label 2025-12-29 20:49:34 +01:00
adam closed this issue 2025-12-29 20:49:34 +01:00
Author
Owner

@arthanson commented on GitHub (Apr 2, 2024):

The upcoming V4 now has the ability to show related information in the dropdown (see below for Device Type entry), there is however no description field. Can you edit this with what fields you would like extra information on specifically, it would be preferable if an extra field wasn't needed - is there an existing field that would provide the needed context information?

Monosnap Add a new device | NetBox 2024-04-02 07-15-57

@arthanson commented on GitHub (Apr 2, 2024): The upcoming V4 now has the ability to show related information in the dropdown (see below for Device Type entry), there is however no `description` field. Can you edit this with what fields you would like extra information on specifically, it would be preferable if an extra field wasn't needed - is there an existing field that would provide the needed context information? ![Monosnap Add a new device | NetBox 2024-04-02 07-15-57](https://github.com/netbox-community/netbox/assets/99642/41783e0a-4935-422a-93c8-f08037d62ccb)
Author
Owner

@steinzi commented on GitHub (Apr 16, 2024):

So if I would have the ability to display the objects own existing description field or the role field in the prefix case, that would be exactly what I needed I'll head over and try the 4.0 beta from what you have shown me that looks like exactly what I need.

Thank you very much for taking the time to answer!

@steinzi commented on GitHub (Apr 16, 2024): So if I would have the ability to display the objects own existing `description ` field or the `role` field in the prefix case, that would be exactly what I needed I'll head over and try the 4.0 beta from what you have shown me that looks like exactly what I need. Thank you very much for taking the time to answer!
Author
Owner

@jeremystretch commented on GitHub (Apr 22, 2024):

At some point the dropdown logic was extended to include the description of each object (if present) by default, so I believe this has already been implemented.

@jeremystretch commented on GitHub (Apr 22, 2024): At some point the dropdown logic was extended to include the description of each object (if present) by default, so I believe this has already been implemented.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#9420