Export templates and query fields

1,737 views
Skip to first unread message

Aaron Street

unread,
Jun 13, 2018, 8:13:28 AM6/13/18
to NetBox
Hi, 

In the Documents is says 

Export templates are written in Django's template language, which is very similar to Jinja2. The list of objects returned from the database is stored in the queryset variable, which you'll typically want to iterate through using a for loop. Object properties can be access by name. 

But how can i output a list of all the possible headers for a particualr type of assest. 

I want to do some thing like below where I am focusing on the device type, but this is not working as I assume I am not using the right name for the primary IP? 

{% for device in queryset %}
{{ device.name }}  {{ device.primary-ipv4 }}
{% endfor %}

It would be nice in the documents is there was an example to extract all the possible field vlaues that can be used to create and output from. So I can see 

possible values are 

device.serialnumber
device.location
..
..
..
..
..





Aaron Street

unread,
Jun 13, 2018, 9:30:59 AM6/13/18
to NetBox
Using the API interface I found a lot of these, but still struggling with outputting the custom fields. onj.cf.<name> does not seem to work, might be becasue spaces in the name? 

Jeremy Stretch

unread,
Jun 13, 2018, 9:31:08 AM6/13/18
to Aaron Street, NetBox
The most direct way to find the available fields and properties is probably to examine the model itself. Each model is defined in models.py under its sub-application. For example, the device model is at dcim.models.Device.

Jeremy


--
You received this message because you are subscribed to the Google Groups "NetBox" group.
To unsubscribe from this group and stop receiving emails from it, send an email to netbox-discuss+unsubscribe@googlegroups.com.
To post to this group, send email to netbox-discuss@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/netbox-discuss/0419bb6f-6972-4d10-ab56-c919d6cbc280%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Aaron Street

unread,
Jun 13, 2018, 9:36:19 AM6/13/18
to NetBox
TYo make it clearer 

if i do 

{{ device.name }} ,{{ device.serial }},{{ device.primary_ip }},{{ device.cf }}

I get the output something like 

ASTERISK-SPARE-SERVER-1  KD1K6Y4 None {&#39;cde-scoped&#39;: None



But if i try 

{{ device.name }} ,{{ device.serial }},{{ device.primary_ip }},{{ device.cf.cde-scoped }}

it fails with a rendering error?




On Wednesday, 13 June 2018 13:13:28 UTC+1, Aaron Street wrote:

Brian Candler

unread,
Jun 14, 2018, 3:53:07 AM6/14/18
to NetBox
On Wednesday, 13 June 2018 14:36:19 UTC+1, Aaron Street wrote:

But if i try 

{{ device.name }} ,{{ device.serial }},{{ device.primary_ip }},{{ device.cf.cde-scoped }}

it fails with a rendering error?


You can't have a minus sign in a bareword like that; it will be treated as a subtraction operator.

It will need to be changed to something like:  {{ device.cf["cde-scoped"] }}
(untested, but if that doesn't work, look through the django templating documentation to find a way to do attribute accesses)

Or you could change your custom field to use an underscore rather than a minus.
Reply all
Reply to author
Forward
0 new messages