Custom scripts driving me nuts (prefix selection)

327 views
Skip to first unread message

Mats Brorson

unread,
Feb 3, 2021, 12:14:56 PM2/3/21
to NetBox
Trying to get a selection of prefixes with no luck.

 I try the following:

    prefix = ObjectVar(
        model=Prefix,
        required=True,
        label='Prefix'
    )  

I have mountains of prefixes, but the list shows nothing when klicking on the dropdown.

Am I missing some parameters here?


Jeremy Stretch

unread,
Feb 4, 2021, 2:19:22 PM2/4/21
to Mats Brorson, NetBox
The ObjectVar widget will populate options using the "name" field by default. Since prefixes do not have a name, you need to specify an alternate field using the display_field argument, like this:
prefix = ObjectVar(
model=Prefix,
required=True,
    display_field='prefix',
label='Prefix'
)
This will populate the list with the value of the "prefix" field from each object returned by the REST API. Hope that helps!

--
You received this message because you are subscribed to the Google Groups "NetBox" group.
To unsubscribe from this group and stop receiving emails from it, send an email to netbox-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/netbox-discuss/c6f8f6f2-6094-4b9e-9379-c50cd9de904dn%40googlegroups.com.


--
Jeremy Stretch
Founder
NetVerity, LLC

Brian Candler

unread,
Dec 19, 2021, 3:03:04 AM12/19/21
to NetBox
Note that this feature was removed from Netbox 3.0 onwards.  The release notes for 3.0 say:

* The `display_field` keyword argument has been removed from custom script ObjectVar and MultiObjectVar fields. These widgets will use the `display` value provided by the REST API.
Reply all
Reply to author
Forward
0 new messages