Allow object properties and custom fields in dropdown context #11265

Closed
opened 2025-12-29 21:42:40 +01:00 by adam · 2 comments
Owner

Originally created by @llamafilm on GitHub (Jun 5, 2025).

NetBox version

v4.3.1

Feature type

Change to existing functionality

Proposed functionality

#15104 allows customizing the appearance of dropdown lists in custom scripts for ObjectVars. I'd like to extend this functionality to support any object property or custom field in the context.

Use case

Here are two examples where I would use this in custom scripts.

We use a space_number custom field on each Location which references an external database run by the real estate team. I'd like to display that as the description like this:

    location = ObjectVar(
        model=Location,
        context={
            "description": "cf__space_number",
        },
     )

Note: that code doesn't work, but it's how I would like it work. If I use id instead, it looks like this:
Image

Another example, in a PowerOutlet variable, I'd like to display the outlet type like this:

    outlet = ObjectVar(
        model=PowerOutlet,
        context = {
            "description": "type.label",
            "disabled": "_occupied",
        },
    )

Database changes

No response

External dependencies

No response

Originally created by @llamafilm on GitHub (Jun 5, 2025). ### NetBox version v4.3.1 ### Feature type Change to existing functionality ### Proposed functionality #15104 allows customizing the appearance of dropdown lists in custom scripts for ObjectVars. I'd like to extend this functionality to support any object property or custom field in the context. ### Use case Here are two examples where I would use this in custom scripts. We use a `space_number` custom field on each Location which references an external database run by the real estate team. I'd like to display that as the description like this: ```py location = ObjectVar( model=Location, context={ "description": "cf__space_number", }, ) ``` Note: that code doesn't work, but it's how I would like it work. If I use `id` instead, it looks like this: ![Image](https://github.com/user-attachments/assets/19559ae6-c8d9-4b32-8d46-ae7625b8edc8) Another example, in a PowerOutlet variable, I'd like to display the outlet type like this: ```py outlet = ObjectVar( model=PowerOutlet, context = { "description": "type.label", "disabled": "_occupied", }, ) ``` ### Database changes _No response_ ### External dependencies _No response_
adam added the type: featurestatus: needs ownerpending closurecomplexity: low labels 2025-12-29 21:42:40 +01:00
adam closed this issue 2025-12-29 21:42:40 +01:00
Author
Owner

@github-actions[bot] commented on GitHub (Sep 11, 2025):

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 (Sep 11, 2025): 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/main/CONTRIBUTING.md).
Author
Owner

@github-actions[bot] commented on GitHub (Oct 12, 2025):

This issue has been automatically closed due to lack of activity. In an effort to reduce noise, please do not comment any further. Note that the core maintainers may elect to reopen this issue at a later date if deemed necessary.

@github-actions[bot] commented on GitHub (Oct 12, 2025): This issue has been automatically closed due to lack of activity. In an effort to reduce noise, please do not comment any further. Note that the core maintainers may elect to reopen this issue at a later date if deemed necessary.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#11265