Replies: 2 comments 1 reply
-
I think the difference you are seeing is that the REST API, while built on top of the Django ORM, does its own separate queries of the related data models to populate those *_count fields, that aren't stored in the Site data model, so a dump of the Site model queryset doesn't have that data. I'm not sure if you can look up other related querysets in jinja in the query set to get that data.
—
Mark Tinberg ***@***.***>
Division of Information Technology-Network Services
University of Wisconsin-Madison
…________________________________
From: Hamit ***@***.***>
Sent: Wednesday, October 5, 2022 7:01 AM
To: netbox-community/netbox ***@***.***>
Cc: Subscribed ***@***.***>
Subject: [netbox-community/netbox] Custom Export Template with count values (Discussion #10566)
Hi!
Netbox version v3.3.4 (also v3.0.7).
I'm trying to make my own template for exporting data to csv format.
Among other parameters, I want to see the following site parameters in the report, an example is taken from one of the sites:
"circuit_count": 2,
"device_count": 2,
"prefix_count": 4,
"rack_count": 0,
"virtualmachine_count": 0,
"vlan_count": 0
Template for the report:
name;slug;status;region;tenant;facility;and;time_zone;physical_address;latitude;longitude;circuit_court;device_count;prefix_count
{% for site in queryset %}{{site.name}};{{site.slug}};{{site.status}};{{site.region}};{{site.tenant}};{{site.facility}};{{site.asn}};{{site.time_zone}};{{site.physical_address}};{{site.latitude}};{{site.longitude}};{{site.circuit_count}};{{site.device_count}};{{site.prefix_count}}
{% endfor %}
And all parameters are successfully unloaded except .*_count.
Please help me solve the problem.
Thank you in advance.
—
Reply to this email directly, view it on GitHub<#10566>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AAS7UM7BWYKSYI7NV2YIMQLWBVU3BANCNFSM6AAAAAAQ5QM6CQ>.
You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
1 reply
-
The JSON format is constructed and includes many fields that aren't in the Site model
https://github.com/netbox-community/netbox/blob/689f11a57322e200ff2340c8492341c751a9da72/netbox/dcim/models/sites.py#L197
The *_count fields in question are added using the Django ORM annotate feature when the Site is queried
https://github.com/netbox-community/netbox/blob/cc00789d35a255e05ea80d9cdd138fe547c670ad/netbox/dcim/api/views.py#L134
And the Site serializer for the REST API adds these along with the URL columns and lookups for related data models like Region or Tenant
https://github.com/netbox-community/netbox/blob/cc00789d35a255e05ea80d9cdd138fe547c670ad/netbox/dcim/api/serializers.py#L127
I'm guessing that the export template implementation is in here but it's not as quick for me to figure out exactly where the queryset is run to see how its presented but I am guessing that it's not doing the view-specific annotations in the bulk exporter, it's a generic query for any model you are exporting
https://github.com/netbox-community/netbox/blob/c4b7ab067a914349abd88398dd9bfef9f6c2f806/netbox/netbox/views/generic/bulk_views.py
—
Mark Tinberg ***@***.***>
Division of Information Technology-Network Services
University of Wisconsin-Madison
…________________________________
From: Hamit ***@***.***>
Sent: Wednesday, October 5, 2022 10:44 AM
To: netbox-community/netbox ***@***.***>
Cc: Mark Tinberg ***@***.***>; Comment ***@***.***>
Subject: Re: [netbox-community/netbox] Custom Export Template with count values (Discussion #10566)
It is not entirely clear why "those *_count fields that are not stored in the site data model", these data are present in the JSON format of the site itself:
GET /api/dcim/sites/338/
HTTP 200 OK
Allow: GET, PUT, PATCH, DELETE, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept
{
"id": 338,
"url": "http://netbox/api/dcim/sites/338 /",
"display": "110401005",
"name": "110401005",
"slug": "110401005",
"status": {
"value": "active",
"label": "Active"
},
"region": {
"id": 11,
"url": "http://netbox/api/dcim/regions/11 /",
"display": "Some Region",
"name": "Some Region",
"slug": "some-region",
"_depth": 1
},
"group": null,
"tenant": {
"id": 6,
"url": "http://netbox/api/tenancy/tenants/6 /",
"display": "Some Site",
"name": "Some Site",
"slug": "some-site"
},
"facility": "110401005",
"asn": 4200001262,
"time_zone": "",
"description": "",
"physical_address": "Some addreses",
"shipping_address": "",
"latitude": "",
"longitude": "",
"contact_name": "",
"contact_phone": "",
"contact_email": "",
"comments": "",
"tags": [],
"custom_fields": {
"replace circuit from": null
},
"created": "2021-04-01",
"last_updated": "2022-09-19T14:49:55.281491+03:00",
"circuit_count": 2,
"device_count": 2,
"prefix_count": 4,
"rack_count": 0,
"virtualmachine_count": 0,
"vlan_count": 0
}
—
Reply to this email directly, view it on GitHub<#10566 (reply in thread)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AAS7UM6PZ3GMHBDX2LE3XBDWBWO5BANCNFSM6AAAAAAQ5QM6CQ>.
You are receiving this because you commented.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi!
Netbox version v3.3.4 (also v3.0.7).
I'm trying to make my own template for exporting data to csv format.
Among other parameters, I want to see the following site parameters in the report, an example is taken from one of the sites:
Template for the report:
And all parameters are successfully unloaded except .*_count.
Please help me solve the problem.
Thank you in advance.
Beta Was this translation helpful? Give feedback.
All reactions