[PR #17481] [CLOSED] Closes: #16837 - Add EmptyStringFilter and type__empty filter on CableFilterSet #15101

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

📋 Pull Request Information

Original PR: https://github.com/netbox-community/netbox/pull/17481
Author: @bctiemann
Created: 9/12/2024
Status: Closed

Base: developHead: 16837-filter-cable-type-empty


📝 Commits (10+)

  • 71945e7 Add EmptyStringFilter and type__empty filter on CableFilterSet
  • 7195f51 Change to EmptyStringMultipleChoiceFilter
  • 2ca4e97 Change to NullableMultipleChoiceFilter
  • 070fafe Add docstring for NullableMultipleChoiceFilter
  • ffcc640 Merge branch 'develop' into 16837-filter-cable-type-empty
  • 6d70c17 Add add_empty_filtering_choice util for empty-value filtering
  • 4675b0c Remove unneeded import
  • d1af212 Fix tests
  • f239b23 Merge branch 'develop' into 16837-filter-cable-type-empty
  • e462e29 Guard against superfluous "choices" param in filter class instantiation

📊 Changes

7 files changed (+41 additions, -8 deletions)

View changed files

📝 netbox/dcim/choices.py (+6 -2)
📝 netbox/dcim/filtersets.py (+2 -2)
📝 netbox/dcim/forms/filtersets.py (+2 -2)
📝 netbox/dcim/tests/test_filtersets.py (+5 -0)
📝 netbox/netbox/filtersets.py (+5 -2)
📝 netbox/utilities/filters.py (+11 -0)
📝 netbox/utilities/forms/utils.py (+10 -0)

📄 Description

Fixes: #16837

Adds EmptyStringFilter from the django-filter documentation's common solutions: https://django-filter.readthedocs.io/en/main/guide/tips.html#filtering-by-an-empty-string

http://127.0.0.1:8000/dcim/cables/?type__empty=true and =false will now work as expected. Filter naming (type__empty) is open to comments.

This same filter can be added to any other filtersets as needed.

Note that this only adds the ability to filter directly via URL; it does not add the empty value to the filter form.


🔄 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/17481 **Author:** [@bctiemann](https://github.com/bctiemann) **Created:** 9/12/2024 **Status:** ❌ Closed **Base:** `develop` ← **Head:** `16837-filter-cable-type-empty` --- ### 📝 Commits (10+) - [`71945e7`](https://github.com/netbox-community/netbox/commit/71945e7bbb3d66c29d8a3cf21c81dec8a03cb97a) Add EmptyStringFilter and type__empty filter on CableFilterSet - [`7195f51`](https://github.com/netbox-community/netbox/commit/7195f51c6cd66a1f12c917251b25bca3a0f2b676) Change to EmptyStringMultipleChoiceFilter - [`2ca4e97`](https://github.com/netbox-community/netbox/commit/2ca4e971dae2246c70501ec6fb513cdc61624231) Change to NullableMultipleChoiceFilter - [`070fafe`](https://github.com/netbox-community/netbox/commit/070fafe3892d2dd60004449dd970086bb4b94f2d) Add docstring for NullableMultipleChoiceFilter - [`ffcc640`](https://github.com/netbox-community/netbox/commit/ffcc640013bf3484d38418ca548b33490c625d3e) Merge branch 'develop' into 16837-filter-cable-type-empty - [`6d70c17`](https://github.com/netbox-community/netbox/commit/6d70c17d7861eaf32fe6bdc0bee830c76bffe328) Add add_empty_filtering_choice util for empty-value filtering - [`4675b0c`](https://github.com/netbox-community/netbox/commit/4675b0cbfb8cd6cb30f0ee509b59aba9719a0ef6) Remove unneeded import - [`d1af212`](https://github.com/netbox-community/netbox/commit/d1af212b0d0eaafb1df563c70245458ed8cba9b2) Fix tests - [`f239b23`](https://github.com/netbox-community/netbox/commit/f239b2337c885c148ca4b8f3847bc5175adca221) Merge branch 'develop' into 16837-filter-cable-type-empty - [`e462e29`](https://github.com/netbox-community/netbox/commit/e462e29c30b69ba081f06de7913caab23a01342a) Guard against superfluous "choices" param in filter class instantiation ### 📊 Changes **7 files changed** (+41 additions, -8 deletions) <details> <summary>View changed files</summary> 📝 `netbox/dcim/choices.py` (+6 -2) 📝 `netbox/dcim/filtersets.py` (+2 -2) 📝 `netbox/dcim/forms/filtersets.py` (+2 -2) 📝 `netbox/dcim/tests/test_filtersets.py` (+5 -0) 📝 `netbox/netbox/filtersets.py` (+5 -2) 📝 `netbox/utilities/filters.py` (+11 -0) 📝 `netbox/utilities/forms/utils.py` (+10 -0) </details> ### 📄 Description ### Fixes: #16837 Adds `EmptyStringFilter` from the django-filter documentation's common solutions: https://django-filter.readthedocs.io/en/main/guide/tips.html#filtering-by-an-empty-string `http://127.0.0.1:8000/dcim/cables/?type__empty=true` and `=false` will now work as expected. Filter naming (`type__empty`) is open to comments. This same filter can be added to any other filtersets as needed. Note that this only adds the ability to filter directly via URL; it does not add the empty value to the filter form. --- <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:20:01 +01:00
adam closed this issue 2025-12-30 00:20:01 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#15101