Skip to content

How to get assigned_object_type_id in netbox script #19505

Answered by pheus
kiksen asked this question in Help Wanted!
Discussion options

You must be logged in to vote

Hi there,

You're absolutely right that if you specifically need the ID of the ContentType, then using:

interface_ct = ContentType.objects.get_for_model(Interface).pk

is the correct way to get it.

However, if your goal is just to assign the interface to the IP address, you don’t need to deal with assigned_object_type_id or assigned_object_id directly. Instead, you can simply do:

newIP.assigned_object = vlanOneInterface

This is cleaner and lets NetBox handle the content type association for you.

Hope that helps!

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@kiksen
Comment options

Answer selected by kiksen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants