[Enhancement] Import by natural key fields#11288
[Enhancement] Import by natural key fields#11288SchrodingersGat wants to merge 16 commits intoinventree:masterfrom
Conversation
- Allow specification of alternative lookup fields for data import
✅ Deploy Preview for inventree-web-pui-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
Pull request overview
This PR introduces natural key field support for data imports in InvenTree, allowing related models to be referenced by human-readable identifiers (like IPN, SKU, MPN) instead of requiring primary key values. This enhancement makes importing data from external sources more intuitive and reduces the need for manual ID lookups.
Changes:
- Added
lookup_related_fieldmethod to perform natural key lookups on related fields during import - Added
get_related_modelmethod to retrieve related model classes for field lookups - Defined
IMPORT_ID_FIELDSon multiple models (Part, PartCategory, PartTestTemplate, Company, ManufacturerPart, SupplierPart, Order, Build) to specify which fields can be used for natural key lookups
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
| src/backend/InvenTree/importer/models.py | Core implementation of natural key lookup functionality with lookup_related_field and get_related_model methods |
| src/backend/InvenTree/part/models.py | Added IMPORT_ID_FIELDS for Part, PartCategory, and PartTestTemplate models |
| src/backend/InvenTree/company/models.py | Added IMPORT_ID_FIELDS for Company, ManufacturerPart, and SupplierPart models |
| src/backend/InvenTree/order/models.py | Added IMPORT_ID_FIELDS to abstract Order model |
| src/backend/InvenTree/build/models.py | Added IMPORT_ID_FIELDS to Build model |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #11288 +/- ##
==========================================
- Coverage 88.04% 88.00% -0.04%
==========================================
Files 1292 1292
Lines 58533 58586 +53
Branches 1943 1943
==========================================
+ Hits 51533 51557 +24
- Misses 6516 6545 +29
Partials 484 484
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|

This PR allows for data importing by "natural key" fields on related models. Instead of forcing data import by primary key (pk) value only, other fields can be used for lookup.
Examples
Related Issues
TODO