Coverage for src/paperap/models/custom_field/model.py: 94%

1"""

2----------------------------------------------------------------------------

3

4 METADATA:

5

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

13

14----------------------------------------------------------------------------

15

16 LAST MODIFIED:

17

18 2025-03-04 By Jess Mann

19

20"""

21

22 from __future__ import annotations

23

24 from datetime import datetime

25 from typing import TYPE_CHECKING, Any, Optional

26

27 from pydantic import Field

28

29 from paperap.models.abstract.model import StandardModel

30

31 if TYPE_CHECKING:

32 from paperap.models.document import DocumentQuerySet

33

34

35 class CustomField(StandardModel):

36 """

37 Represents a custom field in Paperless-NgX.

38 """

39

40 name: str

41 data_type: str | None = None

42 extra_data: dict[str, Any] = Field(default_factory=dict)

43 document_count: int = 0

44

45 model_config = {

46 "arbitrary_types_allowed": True,

47 "populate_by_name": True,

48 "extra": "allow",

49 }

50

51 class Meta(StandardModel.Meta):

52 # Fields that should not be modified

53 read_only_fields = {"slug"}

54

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)