2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-13 10:35:40 +00:00

Add documentation on 'validate_model_deletion' (#7280)

* Add documentation on 'validate_model_deletion'

* Update code inclusion

* Set type annotation

* docstring updates

* Cleanup

* Hide summary

* Remove duplicated code
This commit is contained in:
Oliver
2024-05-21 18:50:56 +10:00
committed by GitHub
parent 1328c3d103
commit c1def12203
2 changed files with 30 additions and 23 deletions

View File

@ -14,29 +14,35 @@ Any of the methods described below can be implemented in a custom plugin to prov
!!! info "Multi Plugin Support"
It is possible to have multiple plugins loaded simultaneously which support validation methods. For example when validating a field, if one plugin returns a null value (`None`) then the *next* plugin (if available) will be queried.
## Model Deletion
Any model which inherits the `PluginValidationMixin` class is exposed to the plugin system for custom deletion validation. Before the model is deleted from the database, it is first passed to the plugin ecosystem to check if it really should be deleted.
A custom plugin may implement the `validate_model_deletion` method to perform custom validation on the model instance before it is deleted.
::: plugin.base.integration.ValidationMixin.ValidationMixin.validate_model_deletion
options:
show_bases: False
show_root_heading: False
show_root_toc_entry: False
show_sources: True
summary: False
members: []
## Model Validation
Any model which inherits the `PluginValidationMixin` mixin class is exposed to the plugin system for custom validation. Before the model is saved to the database (either when created, or updated), it is first passed to the plugin ecosystem for validation.
Any plugin which inherits the `ValidationMixin` can implement the `validate_model_instance` method, and run a custom validation routine.
The `validate_model_instance` method is passed the following arguments:
| Argument | Description |
| --- | --- |
| `instance` | The model instance to be validated |
| `deltas` | A dict of field deltas (if the instance is being updated) |
```python
def validate_model_instance(self, instance, deltas=None):
"""Validate the supplied model instance.
Arguments:
instance: The model instance to be validated
deltas: A dict of field deltas (if the instance is being updated)
"""
...
```
::: plugin.base.integration.ValidationMixin.ValidationMixin.validate_model_instance
options:
show_bases: False
show_root_heading: False
show_root_toc_entry: False
show_sources: True
summary: False
members: []
### Error Messages