[PR #18930] [MERGED] Closes #17841 Allows Tags to be displayed in specified order #15479

Closed
opened 2025-12-30 00:22:10 +01:00 by adam · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/netbox-community/netbox/pull/18930
Author: @jnovinger
Created: 3/17/2025
Status: Merged
Merged: 3/19/2025
Merged by: @arthanson

Base: featureHead: 17841-custom-tag-ordering


📝 Commits (1)

  • f574352 Closes #17841 Allows Tags to be displayed in specified order

📊 Changes

15 files changed (+110 additions, -18 deletions)

View changed files

📝 docs/models/extras/tag.md (+6 -0)
📝 netbox/extras/api/serializers_/tags.py (+2 -2)
📝 netbox/extras/filtersets.py (+1 -1)
📝 netbox/extras/forms/bulk_edit.py (+4 -0)
📝 netbox/extras/forms/bulk_import.py (+5 -1)
📝 netbox/extras/forms/model_forms.py (+6 -2)
netbox/extras/migrations/0124_alter_tag_options_tag_weight.py (+22 -0)
📝 netbox/extras/models/tags.py (+5 -1)
📝 netbox/extras/tables/tables.py (+2 -2)
📝 netbox/extras/tests/test_api.py (+2 -1)
📝 netbox/extras/tests/test_filtersets.py (+8 -1)
📝 netbox/extras/tests/test_models.py (+34 -0)
📝 netbox/extras/tests/test_views.py (+7 -6)
📝 netbox/netbox/models/features.py (+2 -1)
📝 netbox/templates/extras/tag.html (+4 -0)

📄 Description

Fixes: #17841

  • Adds Tag.weight field so users can specify an ordering weight. Valid values are 0-32767.
  • Sets default Tag ordering to ('weight', 'name') so that weights are used for ordering first (lower weights get sorted first) and then names for tie breakers.
  • Sets default TaggingMixin.tags ordering to ('weight', 'name') so that weights are used for ordering first (lower weights get sorted first) and then names for tie breakers. Note: this was required so that calls through an objects .tags related manager would be sorted when called from a template (e.g. so that ordering would work for things like {% for tag in Tag.objects.all %})
  • Updates existing tests and adds tests for default model ordering and related manager ordering defaults.
  • Adds Tag.weight in all the required places.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/netbox-community/netbox/pull/18930 **Author:** [@jnovinger](https://github.com/jnovinger) **Created:** 3/17/2025 **Status:** ✅ Merged **Merged:** 3/19/2025 **Merged by:** [@arthanson](https://github.com/arthanson) **Base:** `feature` ← **Head:** `17841-custom-tag-ordering` --- ### 📝 Commits (1) - [`f574352`](https://github.com/netbox-community/netbox/commit/f574352c17606e6a39afcf025415f15fe6374a56) Closes #17841 Allows Tags to be displayed in specified order ### 📊 Changes **15 files changed** (+110 additions, -18 deletions) <details> <summary>View changed files</summary> 📝 `docs/models/extras/tag.md` (+6 -0) 📝 `netbox/extras/api/serializers_/tags.py` (+2 -2) 📝 `netbox/extras/filtersets.py` (+1 -1) 📝 `netbox/extras/forms/bulk_edit.py` (+4 -0) 📝 `netbox/extras/forms/bulk_import.py` (+5 -1) 📝 `netbox/extras/forms/model_forms.py` (+6 -2) ➕ `netbox/extras/migrations/0124_alter_tag_options_tag_weight.py` (+22 -0) 📝 `netbox/extras/models/tags.py` (+5 -1) 📝 `netbox/extras/tables/tables.py` (+2 -2) 📝 `netbox/extras/tests/test_api.py` (+2 -1) 📝 `netbox/extras/tests/test_filtersets.py` (+8 -1) 📝 `netbox/extras/tests/test_models.py` (+34 -0) 📝 `netbox/extras/tests/test_views.py` (+7 -6) 📝 `netbox/netbox/models/features.py` (+2 -1) 📝 `netbox/templates/extras/tag.html` (+4 -0) </details> ### 📄 Description <!-- Thank you for your interest in contributing to NetBox! Please note that our contribution policy requires that a feature request or bug report be approved and assigned prior to opening a pull request. This helps avoid waste time and effort on a proposed change that we might not be able to accept. IF YOUR PULL REQUEST DOES NOT REFERENCE AN ISSUE WHICH HAS BEEN ASSIGNED TO YOU, IT WILL BE CLOSED AUTOMATICALLY. Please specify your assigned issue number on the line below. --> ### Fixes: #17841 - Adds `Tag.weight` field so users can specify an ordering weight. Valid values are 0-32767. - Sets default `Tag` ordering to `('weight', 'name')` so that weights are used for ordering first (lower weights get sorted first) and then names for tie breakers. - Sets default `TaggingMixin.tags` ordering to `('weight', 'name')` so that weights are used for ordering first (lower weights get sorted first) and then names for tie breakers. **Note:** this was required so that calls through an objects `.tags` related manager would be sorted when called from a template (e.g. so that ordering would work for things like `{% for tag in Tag.objects.all %}`) - Updates existing tests and adds tests for default model ordering and related manager ordering defaults. - Adds `Tag.weight` in all the required places. <!-- Please include a summary of the proposed changes below. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
adam added the pull-request label 2025-12-30 00:22:10 +01:00
adam closed this issue 2025-12-30 00:22:10 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#15479