How to get tags associated with an item through DB SQL query? #12178
-
Hello, I am using a tool to display a range of information about the itens added to the netbox. This tool connects direct to the netbox DB. One information that I need to show is the tags associated to the device type, but I'm having a bad time trying to find the references through the DB schema. I see that the table Extras Taggeditem reference an object_id and a content_type_id but I can't find other table that has these attributes. How can I get the tags associated to the device type. Query that i'm using: SELECT
"public"."dcim_device"."status" AS "status",
"site"."name" AS "ponto",
"site"."description" AS "endereco",
"site"."latitude" AS "latitude",
"site"."longitude" AS "longitude",
"region"."name" AS "regiao",
"ip"."address" AS "ip"
FROM "public"."dcim_device"
LEFT JOIN "public"."dcim_site" "site" ON "public"."dcim_device"."site_id" = "site"."id"
LEFT JOIN "public"."dcim_region" "region" ON "site"."region_id" = "region"."id"
LEFT JOIN "public"."ipam_ipaddress" "ip" ON "public"."dcim_device"."primary_ip4_id" = "ip"."id"
LEFT JOIN "public"."dcim_devicerole" "role" ON "public"."dcim_device"."device_role_id" = "role"."id"
LEFT JOIN "public"."dcim_devicetype" "type" ON "public"."dcim_device"."device_type_id" = "type"."id" Thank you in advance |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
content_type_id refers to an entry in table So, to get tags associated with device type would be something like this:
... with a further join on extras_tag if you want to map the tag_id to the tag name. |
Beta Was this translation helpful? Give feedback.
content_type_id refers to an entry in table
django_content_type
; from that you can get the model and hence the table. object_id is the 'id' within the table in question.So, to get tags associated with device type would be something like this:
... with a further join on extras_tag if you want to map the tag_id to the tag name.