Update CustomFieldValues for a Device

389 views
Skip to first unread message

Petrit Berisha

unread,
Sep 17, 2020, 9:38:21 AM9/17/20
to NetBox
Hello,

I am not able to figure out how to update the value of a custom field.
I am doing the following:

# get the device
>>> d = Device.objects.get(pk=1)

# check
>>> d.cf.keys()
dict_keys(['ios_version', 'is_sn_owner', 'is_covered', 'coverage_end'])

Trying something like:
>>> d.cf['ios_version'] = 'foobar'
'foobar'

This does not work.

Any help on how to update the values of the custom fields?

Thank you.
Kind regards,
Petrit

Brian Candler

unread,
Sep 17, 2020, 10:12:33 AM9/17/20
to NetBox
The "cf" property is a dict containing only a copy of the custom field key/value pairs.  Updating it doesn't touch the database; you have to deal with instances of the CustomFieldValue model.

These may be useful:

Reply all
Reply to author
Forward
0 new messages