Skip to content
Discussion options

You must be logged in to vote

(I don't know if there's an easier way to get from the "Interface" class to its django content_type_id)

Answering my own question:

>>> ContentType.objects.get_for_model(Interface)
<ContentType: dcim | interface>
>>> ContentType.objects.get_for_model(Interface).id
17

You don't even need the id:

>>> IPAddress.objects.filter(assigned_object_id__in=[i.id for i in interfaces],
    assigned_object_type=ContentType.objects.get_for_model(Interface))

Unfortunately, you can't do the following:

>>> IPAddress.objects.filter(assigned_object__in=interfaces)
...
django.core.exceptions.FieldError: Field 'assigned_object' does not generate an automatic reverse relation and
therefore cannot be used for…

Replies: 1 comment 6 replies

Comment options

You must be logged in to vote
6 replies
@candlerb
Comment options

@candlerb
Comment options

Answer selected by WhaleJ84
@WhaleJ84
Comment options

@candlerb
Comment options

@candlerb
Comment options

@WhaleJ84
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants