Skip to content

Allow object properties and custom fields in dropdown context #19658

@llamafilm

Description

@llamafilm

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    complexity: lowRequires minimal effort to implementstatus: needs ownerThis issue is tentatively accepted pending a volunteer committed to its implementationtype: featureIntroduction of new functionality to the application

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions