archivebox.tags.models
Module Contents
Classes
Enhanced QuerySet for KVTag objects. |
|
Very flexible K:V tagging system that allows you to tag any model with any tag. e.g. to tag a Snapshot with 3 tags: KVTag.objects.create(obj=snapshot1, name=’tag1-simple some text’) snapshot1.tags.create(name=’tag1-simple some text’) <- this duplicate would be blocked by an IntegrityError (obj_id + name must be unique) |
|
A base class for models that have tags, adds 0 additional storage overhead to models with 0 tags. |
Data
API
- class archivebox.tags.models.KVTagQuerySet[source]
Bases:
django.db.models.QuerySet
Enhanced QuerySet for KVTag objects.
To list all unique tag names: KVTag.objects.filter(obj__created_by_id=123).names() -> {‘tag1’, ‘tag2’, ‘tag3’}
To list all the Snapshot objects with a given tag: KVTag.objects.filter(name=’tag1’).objects(Snapshot) -> QuerySet[Snapshot]: [snapshot1, snapshot2, snapshot3]
To rename a tag “abcd” to “xyz”: KVTag.objects.filter(name=’abcd’).rename(name=’xyz’) -> QuerySet[KVTag]: [xyz, xyz, xyz]
- non_kvtags() → archivebox.tags.models.KVTagQuerySet[source]
- rename(name: str) → archivebox.tags.models.KVTagQuerySet[source]
- tag_dict() → dict[str, str][source]
Returns a dictionary of dictionaries, where the outer key is the obj_id and the inner key is the tag name. { ‘abcd-2345-2343-234234’: { ‘uuid’: ‘abcd-2345-2343-234234’, ‘sha256’: ‘abc123k3j423kj423kl4j23’, ‘path’: ‘/data/sources/2024-01-02_11-57-51__cli_add.txt’, ‘some-flat-tag’: None, ‘some-other-tag’: None, }, ‘efgh-2345-2343-234234’: { … }, }
- model_classes() → list[Type[django.db.models.Model]][source]
get the unique set of Model classes of objects in this queryset
- class archivebox.tags.models.KVTag[source]
Bases:
ModelWithReadOnlyFields
Very flexible K:V tagging system that allows you to tag any model with any tag. e.g. to tag a Snapshot with 3 tags: KVTag.objects.create(obj=snapshot1, name=’tag1-simple some text’) snapshot1.tags.create(name=’tag1-simple some text’) <- this duplicate would be blocked by an IntegrityError (obj_id + name must be unique)
snapshot1.tags.create(name='ABID', value='snp_abc123k3j423kj423kl4j23') snapshot1.tags.create(name='SHA256', value='1234234abc123k3j423kj423kl4j23') snapshot1.tags.create(name='SAVE_WGET', value='False') snapshot1.tags.create(name='URI', value='file:///data/sources/2024-01-02_11-57-51__cli_add.txt')
- objects: archivebox.tags.models.KVTagManager[source]
‘(…)’
- class archivebox.tags.models.ModelWithKVTags[source]
Bases:
ModelWithReadOnlyFields
A base class for models that have tags, adds 0 additional storage overhead to models with 0 tags.
Snapshot.objects.get(id=’…’).tags.clear() Snapshot.objects.get(id=’…’).tags.create(name=’tag1’) Snapshot.objects.get(id=’…’).tags.create(name=’tag2’, value=’some-value’) Snapshot.objects.get(id=’…’).tags.create(name=’tag3’) Snapshot.objects.get(id=’…’).tags.filter(name=’tag3’).delete() snapshot.objects.get(id=’…’).tag_names -> [‘tag1’, ‘tag2’] snapshot.objects.get(id=’…’).tag_dict -> {‘tag1’: None, ‘tag2’: ‘some-value’} snapshot.objects.get(id=’…’).tag_csv -> ‘tag1,tag2’
- property tag_dict: dict[str, str][source]
{ ‘⭐️’: None, ‘some-other-tag’: None, ‘some tag/testing 234[po4]’: None, ‘uuid’: ‘abcd-2345-2343-234234’, ‘sha256’: ‘abc123k3j423kj423kl4j23’, ‘file’: ‘/data/sources/2024-01-02_11-57-51__cli_add.txt’, }
- get_tag_value(tag_name: str) → str | None[source]
get the value of a tag with the given name pointing to this object, or None if no matching tag exists
- set_tag_value(tag_name: str, tag_value: str | None) → archivebox.tags.models.KVTag[source]
create or update a Tag pointing to this objects with the given name, to the given value