Custom Script to Add Device to Existing or New Tenant #17905
-
Hello everyone, I would like to know if it’s possible to use a custom python script in NetBox to achieve the following, script without the API:
Any guidance on implementing this functionality would be greatly appreciated! Thank you in advance for your help! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
The function you should use in your custom NetBox script is Hope this helps! Example:
Docs:https://docs.djangoproject.com/en/5.1/ref/models/querysets/#get-or-create |
Beta Was this translation helpful? Give feedback.
The function you should use in your custom NetBox script is
get_or_create()
. It returns a tuple of (object, created), where object is the retrieved or created object and created is a boolean specifying whether a new object was created.Hope this helps!
Example:
https://github.com/netbox-community/netbox/blob/4ca2b21a706f86fdb4ff5bf1940960f73ed74530/netbox/utilities/testing/utils.py#L47C1-L50C107