refactor(backend): move mixins to generic (#13293)

* move mixins to generic

* fix imports

* fix import

* move InvenTreePermissionCheckMixin

* move base models

* move InvenTreeAuditMixin

* move PathStringMixin

* move ContentTypeMixin

* move MetadataMixin, PluginValidationMixin

* move ReferenceIndexingMixin

* fix import paths

* update doc paths

* fix imports

* internalize diff base

* add legacy imports

* rename metadata mixin

* rename PathStringMixin

* rename PluginValidationMixin

* rename ReferenceIndexingMixin

* add changelog entry

* document base clases

* add docs for model mixins

* add the rest of doc strings
This commit is contained in:
Matthias Mair authored and GitHub committed 2026-11-23 09:44:54 +11:00
1 parent 8ebb7a0e20
commit afc88f56e8
39 files changed
+2172 -2048

No files matched your search

+1 -1
View File
@@ -86,7 +86,7 @@ To try it just copy the file to src/InvenTree/plugins and restart the server. Op
To implement a custom internal barcode format, the `generate(...)` method from the Barcode Mixin needs to be overridden. Then the plugin can be selected at `System Settings > Barcodes > Barcode Generation Plugin`.
```python
from InvenTree.models import InvenTreeBarcodeMixin
from generic.models.modelmixins import InvenTreeBarcodeMixin
from plugin import InvenTreePlugin
from plugin.mixins import BarcodeMixin
+66 -2
View File
@@ -23,14 +23,78 @@ This configuration ensures that Django recognizes the plugin as a valid applicat
## Base classes
A typical Django model class is based on `django.db.models.Model`, which provides the core functionality for defining database models in Django. Alternatively, `InvenTree.models.InvenTreeModel` comes with a few additional core integrations (content type association, [plugin validation](./mixins/validation.md)) or `InvenTree.models.InvenTreeMetadataModel` which also includes [model metadata](./metadata.md) support for the model instances.
A typical Django model class is based on `django.db.models.Model`, which provides the core functionality for defining database models in Django.
Alternatively, `generic.models.base`contains a few base classes that plugins can also use.
### InvenTreeModel
Add support for content type association and [plugin validation](./mixins/validation.md).
### InvenTreeMetadataModel
Adds everything in InvenTreeModel, and adds support for [model metadata](./metadata.md).
### InvenTreeTree
For Tree models using django-mptt for hierarchies, also include content type association.
## Generic Model Mixins
### MetadataMixin
Most common mechanisms contained in InvenTree's own models are exposed in the `generic.models` module as a set of mixins that often also have detection for frontend components to provide functions automatically.
### InvenTreeAttachmentMixin
Adds support for use of [generic attachments](../concepts/attachments.md) with a models instances.
### InvenTreeAuditMixin
Adds support for [audit tracking](../concepts/audit.md) of model instances, including API and user interface generation.
### InvenTreeBarcodeMixin
Adds fields and functions for linking a [barcode](../barcodes/index.md) against model instances including lookup, assignment, and validation of barcodes against the API.
### InvenTreeImageMixin
Adds a `image` field to the model and automatic thumbnail generation for the uploaded images. This image can also be referenced in [reports](../report/report.md).
You must define a constant `IMAGE_RENAME` on the model class pointing to the function in your model that handles renaming uploaded images.
### InvenTreeMetadataMixin
Adds support for [model metadata](./metadata.md) support, allowing additional information to be attached to model instances. This metadata can be accessed and manipulated through the InvenTree API or by other plugins.
### InvenTreeNoteMixin
Adds support for defining and managing [notes](../concepts/notes.md) against model instances.
### InvenTreeParameterMixin
Adds support for [parameters](../concepts/parameters.md), allowing your models to use the parameter mechanism including proper permission checks and integration with the InvenTree API.
### InvenTreePathStringMixin
Adds a number of fields to support having hierarchical path strings persisted on model instances automatically. Used by parts and stock item.
!!! warning "Warning"
Use only after understanding the added computational and database load overhead.
### InvenTreePluginValidationMixin
Adds functions that extend save and delete operations of the model to call [plugins for validation](./mixins/validation.md) before committing changes to the database.
### InvenTreeReferenceIndexingMixin
Adds support for generating, validating and parsing [instance references](../settings/reference.md). Also adds a `reference_int` field that stores a converted value for the reference for use in ordering and indexing operations.
An optional constant `REFERENCE_PATTERN_SETTING` on the model class can be pointed to a settings name that will be used to control the [reference pattern](../settings/reference.md).
### InvenTreeTagsMixin
Adds the required mechanism for defining [tags](../concepts/tags.md) for model instances.