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

16 statements  

« prev     ^ index     » next       coverage.py v7.6.12, created at 2025-03-18 12:26 -0400

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 

22from __future__ import annotations 

23 

24from datetime import datetime 

25from typing import TYPE_CHECKING, Any, Optional 

26 

27from pydantic import Field 

28 

29from paperap.models.abstract.model import StandardModel 

30 

31if TYPE_CHECKING: 

32 from paperap.models.document import DocumentQuerySet 

33 

34 

35class 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)