Permissions, nested objects

66 views
Skip to first unread message

Denis Tsygankov

unread,
May 20, 2021, 7:45:15 AM5/20/21
to NetBox
I want to get a permission to delete devices with a particular manufacturer name.
For example, I have a manufacturer named "GRSM". As per my logic, I need a constraint, something as: 
[{"device_type__manufacturer": {"name": "GRSM"}}]
But got the error below while trying to create it:
--------------------------------
<class 'TypeError'>

Field 'id' expected a number but got {'name': 'GRSM'}.

Python version: 3.7.3
NetBox version: 2.11.3
--------------------------------
What is the correct way to do what I want?

Denis Tsygankov

unread,
May 20, 2021, 8:08:47 AM5/20/21
to NetBox
I was able to do what I want. Instead of the manufacturer name I've used its ID. My final constraint is: [{"device_type__manufacturer": 26}]

Jeremy Stretch

unread,
May 20, 2021, 8:12:11 AM5/20/21
to Denis Tsygankov, NetBox
You can use dunders (double underscores) to navigate related object attributes. So to match many manufacturer name, you would do:

  [{"device_type__manufacturer__name": "GRSM"}]

Hope that helps!

Jeremy Stretch
Distinguished Engineer, NS1
Office of the CTO
 
website: ns1.com
email: jstretch@ns1.com
 
twitterlinkedin
 
banner


--
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/42587ea9-45de-44a7-9642-9ebbe626897bn%40googlegroups.com.

Brian Candler

unread,
May 20, 2021, 8:12:17 AM5/20/21
to NetBox
You could also try {"device_type__manufacturer__name": "GRSM"}  [untested]

Denis Tsygankov

unread,
May 20, 2021, 8:16:01 AM5/20/21
to NetBox
Many thanks, Jeremy and Brian!
Reply all
Reply to author
Forward
0 new messages