Coverage for src/paperap/models/document_type/model.py: 94%
18 statements
« prev ^ index » next coverage.py v7.6.12, created at 2025-03-12 23:40 -0400
« prev ^ index » next coverage.py v7.6.12, created at 2025-03-12 23:40 -0400
1"""
2----------------------------------------------------------------------------
4 METADATA:
6 File: document_type.py
7 Project: paperap
8 Created: 2025-03-04
9 Version: 0.0.5
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, Optional
27from paperap.models.abstract.model import StandardModel
28from paperap.models.document_type.queryset import DocumentTypeQuerySet
29from paperap.models.mixins.models import MatcherMixin
31if TYPE_CHECKING:
32 from paperap.models.document import Document, DocumentQuerySet
35class DocumentType(StandardModel, MatcherMixin):
36 """
37 Represents a document type in Paperless-NgX.
39 Attributes:
40 name: The name of the document type.
41 slug: A unique identifier for the document type.
42 match: The pattern used for matching documents.
43 matching_algorithm: The algorithm used for matching.
44 is_insensitive: Whether the matching is case insensitive.
45 document_count: The number of documents of this type.
46 owner: The owner of the document type.
47 user_can_change: Whether the user can change the document type.
49 Returns:
50 A new instance of DocumentType.
52 Examples:
53 # Create a new DocumentType instance
54 doc_type = DocumentType(name="Invoice", slug="invoice", match="INV-*")
56 """
58 name: str
59 slug: str | None = None
60 document_count: int = 0
61 owner: int | None = None
62 user_can_change: bool | None = None
64 class Meta(StandardModel.Meta):
65 # Fields that should not be modified
66 read_only_fields = {"slug", "document_count"}
67 queryset = DocumentTypeQuerySet
69 @property
70 def documents(self) -> "DocumentQuerySet":
71 """
72 Get documents with this document type.
74 Returns:
75 A DocumentQuerySet containing documents of this type.
77 Examples:
78 # Get all documents of this type
79 documents = doc_type.documents
80 Get documents with this document type.
82 """
83 return self._client.documents().all().document_type_id(self.id)