mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-12 18:15:40 +00:00
Add 'Tag' management (#4367)
* 'Tag' management Fixes #83 * Add for ManufacturerPart, SupplierPart * Add tags for StockLocation, StockItem * fix serializer definition * add migrations * update pre-commit * bump dependencies * revert updates * set version for bugbear * remove bugbear * readd bugbear remove isort * and remove bugbear again * remove bugbear * make tag fields not required * add ruleset * Merge migrations * fix migrations * add unittest for detail * test tag add * order api * reduce database access * add tag modification test * use overriden serializer to ensuer the manager is always available * fix typo * fix serializer * increae query thershold by 1 * move tag serializer * fix migrations * content_types are changing between tests - removing them * remove unneeded fixture * Add basic docs * bump API version * add api access to the docs * add python code * Add tags to search and filters for all models
This commit is contained in:
61
docs/docs/extend/plugins/tags.md
Normal file
61
docs/docs/extend/plugins/tags.md
Normal file
@ -0,0 +1,61 @@
|
||||
---
|
||||
title: Item Tags
|
||||
---
|
||||
|
||||
## Tags
|
||||
|
||||
Several models in InvenTree can be tagged with arbitrary tags. Tags are useful for grouping items together. This can be used to mark items with a plugin or to group items together for a particular theme. Tags are meant to be used by programms and are not visible to the end user.
|
||||
Tags are shared between all models that can be tagged.
|
||||
|
||||
The following models can be tagged:
|
||||
- [Parts](../../part/part.md) and [Supplier Parts](../../order/company#supplier-parts)/[Manufacturer Part](../../order/company#manufacturer-parts)
|
||||
- [Stock Items](../../stock/stock.md#stock-item) / [Stock Location](../../stock/stock.md#stock-location)
|
||||
|
||||
|
||||
## Accessing Tags
|
||||
|
||||
### Plugin Access
|
||||
|
||||
The `tags` field can be accessed and updated directly from custom plugin code, as follows:
|
||||
|
||||
```python
|
||||
from part.models import Part
|
||||
|
||||
# Show tags for a particular Part instance
|
||||
part = Part.objects.get(pk=100)
|
||||
print(part.tags)
|
||||
|
||||
> {['Tag1', 'Another Tag']}
|
||||
|
||||
# Tags can also be accessed via tags.all()
|
||||
print(part.tags.all())
|
||||
|
||||
> {['Tag1', 'Another Tag']}
|
||||
|
||||
# Add tag
|
||||
part.tags.add('Tag 2')
|
||||
print(part.tags)
|
||||
|
||||
> {['Tag1', 'Tag 2', 'Another Tag']}
|
||||
|
||||
# Remove tag
|
||||
part.tags.remove('Tag1')
|
||||
print(part.tags)
|
||||
|
||||
> {['Tag 2', 'Another Tag']}
|
||||
|
||||
# Filter by tags
|
||||
Part.objects.filter(tags__name__in=["Tag1", "Tag 2"]).distinct()
|
||||
```
|
||||
|
||||
### API Access
|
||||
|
||||
For models which provide tags, access is also provided via the API. The tags are exposed via the detail endpoint for the models starting from version 111.
|
||||
|
||||
Tags can be cached via PATCH or POST requests. The tags are provided as a json formatted list of strings. The tags are note case sensitive and must be unique across the instance - else the exsisting tag gets assigned. The tags are not sorted and the order is not guaranteed.
|
||||
|
||||
```json
|
||||
{
|
||||
"tags": '["foo", "bar"]'
|
||||
}
|
||||
```
|
@ -166,6 +166,7 @@ nav:
|
||||
- Installation: extend/plugins/install.md
|
||||
- Developing a Plugin: extend/how_to_plugin.md
|
||||
- Model Meatadata: extend/plugins/metadata.md
|
||||
- Tags: extend/plugins/tags.md
|
||||
- Plugin Mixins:
|
||||
- Action Mixin: extend/plugins/action.md
|
||||
- API Mixin: extend/plugins/api.md
|
||||
|
Reference in New Issue
Block a user