Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom fields - Allow use of query params for filtering object selection #16782

Closed
samk-acw opened this issue Jul 1, 2024 · 7 comments
Closed
Assignees
Labels
complexity: low Requires minimal effort to implement status: accepted This issue has been accepted for implementation type: feature Introduction of new functionality to the application
Milestone

Comments

@samk-acw
Copy link
Contributor

samk-acw commented Jul 1, 2024

NetBox version

v4.0.6

Feature type

Change to existing functionality

Proposed functionality

Object type custom fields are very useful for creating new relationships between objects, but it has no ability to filter the selection list, any object of that type can be selected which may not be desirable depending on the intended purpose of the custom field.

The DynamicModelChoice mixins already support filtering the API requests using the query_params dict, I propose that this be added as an option to specify in the custom field definition.

Use case

Allowing filtering of the object choice selection would allow additional business logic to be applied and provide a more intuitive experience for the end user who is using the field.
For example, I have a custom field defined on Circuits to select an IP Address - with a query params definition I could limit it to show only 'active' IP addresses, and chain it to tenant field with $tenant to only list IPs that are assigned to the tenant of that circuit.

Database changes

CustomField model will need an additional field to store the parameter

External dependencies

none

@samk-acw samk-acw added status: needs triage This issue is awaiting triage by a maintainer type: feature Introduction of new functionality to the application labels Jul 1, 2024
@jeffgdotorg jeffgdotorg removed their assignment Jul 3, 2024
@jeffgdotorg jeffgdotorg added status: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation complexity: low Requires minimal effort to implement and removed status: needs triage This issue is awaiting triage by a maintainer labels Jul 3, 2024
@jeffgdotorg
Copy link
Contributor

Thanks for your interest in helping improve NetBox.

Your proposal and use case look good enough to work with, so I'm moving your issue along to needs owner status. If you or another developer with the requisite skills and capacity would like to work it through to a PR, please say so and a maintainer will assign the issue to you.

@samk-acw
Copy link
Contributor Author

samk-acw commented Jul 4, 2024

Hi Jeff, I've done a proof-of-concept test that worked, so I'm happy work on a PR.

rough plan is:

  1. add a JSONField to customfield model called "object choice filter"
  2. add field to customfield form, template, and api serializer
  3. modify to_form_field() function to load field value into query_params
  4. add to documentation

@samk-acw
Copy link
Contributor Author

Hi @jeffgdotorg, just checking on the status of this. Can I provide a PR?
Thanks

@jeremystretch jeremystretch added status: accepted This issue has been accepted for implementation and removed status: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation labels Jul 18, 2024
@jeremystretch
Copy link
Member

@samk-acw thanks for your interest, I've assigned this to you.

@jeremystretch
Copy link
Member

It appears this FR was tagged for implementation prematurely. Introducing a new field on a model can only be done in a new minor release: This should have been tagged for milestone assignment. Unfortunately we're in the process of rolling up the last pieces of open work for v4.1 right now.

@samk-acw if you'd like to rebase your PR #16957 off of the feature branch for the upcoming v4.1 release, we can try to slip it in, but I can't make any promises. Apologies for the confusion.

@samk-acw
Copy link
Contributor Author

Hi @jeremystretch, thanks for clarifying, I've deleted my original branch and done a new PR based from the feature branch now.
Made a bit of a mess while trying to rebase it on the original, hopefully I've cleaned that all up.

@jeremystretch
Copy link
Member

This is a good reminder that we really need to get #14656 implemented. The custom field form is a mess.

@jeremystretch jeremystretch added this to the v4.1 milestone Jul 26, 2024
jeremystretch added a commit that referenced this issue Jul 29, 2024
* Fixes #16782: Add object filtering for custom fields

* Add validation for related_object_filter

* Extend documentation & misc cleanup

---------

Co-authored-by: Jeremy Stretch <jstretch@netboxlabs.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
complexity: low Requires minimal effort to implement status: accepted This issue has been accepted for implementation type: feature Introduction of new functionality to the application
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants