Skip to content

Conversation

@Jathn
Copy link
Contributor

@Jathn Jathn commented Jul 30, 2025

Closes #18843: using color name in cable export

The changes made allow for the name of the color to be exported when exporting cables. This applies to both full table export "All data (csv)" and using custom export templates.

Changes made:

  • Add a color_name property to cable model
  • Add color_name to cable table

@jeremystretch jeremystretch requested review from a team and arthanson and removed request for a team July 30, 2025 16:39
Copy link
Collaborator

@arthanson arthanson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you add Color Name to the cable list and then sort on the color name you will get an exception.

Traceback (most recent call last):
  File "/Users/ahanson/dev/work/netbox/venv/lib/python3.13/site-packages/django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
  File "/Users/ahanson/dev/work/netbox/venv/lib/python3.13/site-packages/django/core/handlers/base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/Users/ahanson/dev/work/netbox/venv/lib/python3.13/site-packages/django/views/generic/base.py", line 104, in view
    return self.dispatch(request, *args, **kwargs)
           ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ahanson/dev/work/netbox/netbox/netbox/views/generic/base.py", line 77, in dispatch
    return super().dispatch(request, *args, **kwargs)
           ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ahanson/dev/work/netbox/netbox/utilities/views.py", line 125, in dispatch
    return super().dispatch(request, *args, **kwargs)
           ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ahanson/dev/work/netbox/netbox/utilities/views.py", line 39, in dispatch
    return super().dispatch(request, *args, **kwargs)
           ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ahanson/dev/work/netbox/venv/lib/python3.13/site-packages/django/views/generic/base.py", line 143, in dispatch
    return handler(request, *args, **kwargs)
  File "/Users/ahanson/dev/work/netbox/netbox/netbox/views/generic/bulk_views.py", line 181, in get
    table = self.get_table(self.queryset, request, has_bulk_actions)
  File "/Users/ahanson/dev/work/netbox/netbox/netbox/views/generic/mixins.py", line 65, in get_table
    table.configure(request)
    ~~~~~~~~~~~~~~~^^^^^^^^^
  File "/Users/ahanson/dev/work/netbox/netbox/netbox/tables/tables.py", line 180, in configure
    self.order_by = ordering
    ^^^^^^^^^^^^^
  File "/Users/ahanson/dev/work/netbox/venv/lib/python3.13/site-packages/django_tables2/tables.py", line 542, in order_by
    self.data.order_by(self._order_by)
    ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^
  File "/Users/ahanson/dev/work/netbox/venv/lib/python3.13/site-packages/django_tables2/data.py", line 224, in order_by
    self.data = self.data.order_by(*order_by_accessors)
                ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ahanson/dev/work/netbox/venv/lib/python3.13/site-packages/django/db/models/query.py", line 1722, in order_by
    obj.query.add_ordering(*field_names)
    ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
  File "/Users/ahanson/dev/work/netbox/venv/lib/python3.13/site-packages/django/db/models/sql/query.py", line 2291, in add_ordering
    self.names_to_path(item.split(LOOKUP_SEP), self.model._meta)
    ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ahanson/dev/work/netbox/venv/lib/python3.13/site-packages/django/db/models/sql/query.py", line 1805, in names_to_path
    raise FieldError(
    ...<2 lines>...
    )
django.core.exceptions.FieldError: Cannot resolve keyword 'color_name' into field. Choices are: _abs_length, bookmarks, color, comments, created, custom_field_data, description, id, journal_entries, label, last_updated, length, length_unit, status, subscriptions, tagged_items, tags, tenant, tenant_id, terminations, type

@Jathn
Copy link
Contributor Author

Jathn commented Aug 1, 2025

Pardon the oversight. I've now disabled sorting, since the plan of the implementation wasn't to represent the full feature set of a field in the first place.

@Jathn Jathn requested a review from arthanson August 1, 2025 15:34
Copy link
Collaborator

@arthanson arthanson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Jathn !

@arthanson arthanson merged commit c7b6866 into netbox-community:main Aug 1, 2025
3 checks passed
@Jathn Jathn deleted the 18843-export-color-name branch August 10, 2025 15:26
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 10, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Export Color name instead of of Hex code

2 participants