Custom field values should be accessible in export templates #438

Closed
opened 2025-12-29 16:22:10 +01:00 by adam · 4 comments
Owner

Originally created by @jeremystretch on GitHub (Sep 16, 2016).

Currently, there is no way to access an object's custom fields from within an export template. Ideally, these fields should be accessible similar to any real attribute. For example, an object with a custom field named color should be accessible as such:

{% for obj in queryset %}
    Color: {{ obj.cf.color }}
{% endfor %}

We want to use a designated attribute (cf) to avoid collisions with existing attributes.

Originally created by @jeremystretch on GitHub (Sep 16, 2016). Currently, there is no way to access an object's custom fields from within an export template. Ideally, these fields should be accessible similar to any real attribute. For example, an object with a custom field named `color` should be accessible as such: ``` {% for obj in queryset %} Color: {{ obj.cf.color }} {% endfor %} ``` We want to use a designated attribute (`cf`) to avoid collisions with existing attributes.
adam added the type: feature label 2025-12-29 16:22:10 +01:00
adam closed this issue 2025-12-29 16:22:11 +01:00
Author
Owner

@jeremystretch commented on GitHub (Sep 21, 2016):

Of course, immediately after releasing v1.6.1, I realize that I never finished renaming the get_custom_fields method, so cf() doesn't actually work inside export templates.

@jeremystretch commented on GitHub (Sep 21, 2016): Of course, immediately after releasing v1.6.1, I realize that I never finished renaming the `get_custom_fields` method, so `cf()` doesn't actually work inside export templates.
Author
Owner

@jeremystretch commented on GitHub (Sep 21, 2016):

Fixed in 325d96dabb

@jeremystretch commented on GitHub (Sep 21, 2016): Fixed in 325d96dabb050ac6edb937cb7210598fff83a265
Author
Owner

@DevilWAH commented on GitHub (Jun 13, 2018):

Hi I know this is closed but what if the custome fieled has space in name? "CDE Scoped"

{{ device.name }} ,{{ device.serial }},{{ device.primary_ip }},{{ device.cf }}
works, if a bit messy.
but
{{ device.name }} ,{{ device.serial }},{{ device.primary_ip }},{{ device.cf.cde-scoped ]]

gives a rendering error?

@DevilWAH commented on GitHub (Jun 13, 2018): Hi I know this is closed but what if the custome fieled has space in name? "CDE Scoped" {{ device.name }} ,{{ device.serial }},{{ device.primary_ip }},{{ device.cf }} works, if a bit messy. but {{ device.name }} ,{{ device.serial }},{{ device.primary_ip }},{{ device.cf.cde-scoped ]] gives a rendering error?
Author
Owner

@jeremystretch commented on GitHub (Jun 13, 2018):

Didn't think spaces were valid in the name but it appears they are. They shouldn't be. Just use an underscore or hyphen in the field name instead of a space. You can set a separate human-friendly label to be displayed on the UI.

@jeremystretch commented on GitHub (Jun 13, 2018): Didn't think spaces were valid in the name but it appears they are. They shouldn't be. Just use an underscore or hyphen in the field name instead of a space. You can set a separate human-friendly label to be displayed on the UI.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#438