Repository navigation
[API] Enhanced filtering for generic parameters - #11383
Conversation
- Allow filtering by model ID as well as model type
- Required for the parameteric data tables - Enable filtering by base model ID - Enable filtering by related model ID
✅ Deploy Preview for inventree-web-pui-preview canceled.
|
There was a problem hiding this comment.
Pull request overview
This PR enhances the filtering capabilities for generic parameter templates to fix an issue where part parameters displayed columns for all templates regardless of category scope. The solution introduces three new API filters (exists_for_model_id, exists_for_related_model, and exists_for_related_model_id) that enable scoped filtering of parameter templates based on related models like categories.
Changes:
- Added new API filters to restrict parameter templates to those with parameters associated with specific model instances and their related models
- Updated frontend components to pass related model information for category-scoped filtering
- Bumped API version to 455 to reflect new filtering capabilities
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/frontend/src/tables/part/ParametricPartTable.tsx | Passes category information to enable category-scoped parameter filtering |
| src/frontend/src/tables/general/ParametricDataTable.tsx | Adds support for related model filtering parameters in API requests |
| src/backend/InvenTree/common/api.py | Implements three new filter methods for scoped parameter template queries |
| src/backend/InvenTree/InvenTree/api_version.py | Increments API version and documents new filter additions |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Merging this PR will improve performance by 21.96%
|
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #11383 +/- ##
========================================
Coverage 88.03% 88.04%
========================================
Files 1292 1292
Lines 58540 58655 +115
Branches 1943 1943
========================================
+ Hits 51538 51644 +106
- Misses 6518 6527 +9
Partials 484 484
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
Ref: #11381
Problem Description
With the introduction of generic parameters the filtering of "part parameters" based on the part category has been broken.
This means that when viewing a given part category, the parametric data table displays columns for every parameter which exists for a part, and is not scope limited to the category. This creates a visually cluttered table with a lot of irrelevant parameters.
e.g. for the "capacitors" category, all parameter templates are displayed including "resistance" "thread" (etc)
Solution
The solution is to add some new "generic" filters for the
ParameterTemplateAPIexists_for_model_idexists_for_modelfilterexists_for_related_modelcategoryforpart. Needs to be used in conjunction with theexists_for_related_model_idfilterexists_for_related_model_idSo this approach lets us make queries such as:
Return all ParameterTemplate instances for which there are greater than zero Template instances linked with the Part model, for any Part which exists within a provided category
And the API query to achieve the above is structured as:
/api/parameter/template/?active=true&ordering=name&for_model=part&exists_for_model=part&exists_for_related_model=category&exists_for_related_model_id=6Result
And here we can see that back in the "capacitors" category, only the relevant columns are displayed:
Testing