Coverage for src/paperap/models/custom_field/queryset.py: 69%

13 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: queryset.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 

24import logging 

25from typing import TYPE_CHECKING, Any, Optional, Self, Union 

26 

27from paperap.models.abstract.queryset import BaseQuerySet, StandardQuerySet 

28from paperap.models.mixins.queryset import HasDocumentCount 

29 

30if TYPE_CHECKING: 

31 from paperap.models.custom_field.model import CustomField 

32 

33logger = logging.getLogger(__name__) 

34 

35 

36class CustomFieldQuerySet(StandardQuerySet["CustomField"], HasDocumentCount): 

37 """ 

38 QuerySet for Paperless-ngx custom fields with specialized filtering methods. 

39 """ 

40 

41 def name(self, name: str, *, exact: bool = True) -> Self: 

42 """ 

43 Filter custom fields by name. 

44 

45 Args: 

46 name: The custom field name to filter by 

47 exact: If True, match the exact name, otherwise use contains 

48 

49 Returns: 

50 Filtered CustomFieldQuerySet 

51 

52 """ 

53 if exact: 

54 return self.filter(name=name) 

55 return self.filter(name__contains=name) 

56 

57 def data_type(self, data_type: str) -> Self: 

58 """ 

59 Filter custom fields by data type. 

60 

61 Args: 

62 data_type: The data type to filter by (e.g., "string", "integer", "boolean", "date") 

63 

64 Returns: 

65 Filtered CustomFieldQuerySet 

66 

67 """ 

68 return self.filter(data_type=data_type)