Coverage for src/paperap/models/tag/model.py: 93%
28 statements
« prev ^ index » next coverage.py v7.6.12, created at 2025-03-22 16:02 -0400
« prev ^ index » next coverage.py v7.6.12, created at 2025-03-22 16:02 -0400
1"""
2----------------------------------------------------------------------------
4 METADATA:
6 File: tag.py
7 Project: paperap
8 Created: 2025-03-04
9 Version: 0.0.9
10 Author: Jess Mann
11 Email: jess@jmann.me
12 Copyright (c) 2025 Jess Mann
14----------------------------------------------------------------------------
16 LAST MODIFIED:
18 2025-03-04 By Jess Mann
20"""
22from __future__ import annotations
24from datetime import datetime
25from typing import TYPE_CHECKING, Any
27from pydantic import Field, field_validator
29from paperap.const import MatchingAlgorithmType
30from paperap.models.abstract.model import StandardModel
31from paperap.models.mixins.models import MatcherMixin
32from paperap.models.tag.queryset import TagQuerySet
34if TYPE_CHECKING:
35 from paperap.models.document import Document, DocumentQuerySet
38class Tag(StandardModel, MatcherMixin):
39 """
40 Represents a tag in Paperless-NgX.
41 """
43 name: str | None = None
44 slug: str | None = None
45 colour: str | int | None = Field(alias="color", default=None)
46 is_inbox_tag: bool | None = None
47 document_count: int = 0
48 owner: int | None = None
49 user_can_change: bool | None = None
51 # Alias for colour
52 @property
53 def color(self) -> str | int | None:
54 """Alias for colour field."""
55 return self.colour
57 @color.setter
58 def color(self, value: str | int | None) -> None:
59 """Setter for colour field."""
60 self.colour = value
62 class Meta(StandardModel.Meta):
63 # Fields that should not be modified
64 read_only_fields = {"slug", "document_count"}
65 queryset = TagQuerySet
67 @property
68 def documents(self) -> "DocumentQuerySet":
69 """
70 Get documents with this tag.
72 Returns:
73 List of documents.
75 """
76 return self._client.documents().all().tag_id(self.id)