Coverage for src/paperap/models/custom_field/model.py: 94%
16 statements
« prev ^ index » next coverage.py v7.6.12, created at 2025-03-11 21:37 -0400
« prev ^ index » next coverage.py v7.6.12, created at 2025-03-11 21:37 -0400
1"""
2----------------------------------------------------------------------------
4 METADATA:
6 File: custom_field.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 pydantic import Field
29from paperap.models.abstract.model import StandardModel
31if TYPE_CHECKING:
32 from paperap.models.document import DocumentQuerySet
35class CustomField(StandardModel):
36 """
37 Represents a custom field in Paperless-NgX.
38 """
40 name: str
41 data_type: str | None = None
42 extra_data: dict[str, Any] = Field(default_factory=dict)
43 document_count: int = 0
45 model_config = {
46 "arbitrary_types_allowed": True,
47 "populate_by_name": True,
48 "extra": "allow",
49 }
51 class Meta(StandardModel.Meta):
52 # Fields that should not be modified
53 read_only_fields = {"slug"}
55 @property
56 def documents(self) -> "DocumentQuerySet":
57 """
58 Get documents with this custom field.
59 """
60 return self._client.documents().all().has_custom_field_id(self.id)