Setting Custom Fields via Scripts

876 views
Skip to first unread message

johannes...@googlemail.com

unread,
Sep 29, 2020, 4:34:01 AM9/29/20
to NetBox
Hello

I have a script (script as in netbox script that works directly with the netbox objects, not as in script that uses the REST api) that has to set a custom field of a device.
Setting regular values like name, device_type, ... is not a prolem. but the custom fields appear to be some kind of special solution. I have not found an example on how to do that properly. I tried to take a look at the netbox code, because somewhere netbox has to set the custom fields but I have not found it, which is probably because I am not deep enough into django.

Has someone found a nice example or has some code to share?

Greetings
Jo

Brian Candler

unread,
Sep 29, 2020, 4:44:36 AM9/29/20
to NetBox
Yes, it has been discussed before on this list. See:
which links to other posts with examples.

Johannes Erwerle

unread,
Sep 29, 2020, 5:50:11 AM9/29/20
to netbox-...@googlegroups.com
Thanks, my script works now. The examples are a bit dated on the import
side of things, the required imports are currently (v2.9.4):

from extras.models import CustomField, CustomFieldChoice, CustomFieldValue
from django.contrib.contenttypes.models import ContentType

But apparently the way CustomFields work will be changed in v2.10.

Greetings
Jo
Reply all
Reply to author
Forward
0 new messages