Coverage for src/paperap/models/custom_field/queryset.py: 71%
14 statements
« prev ^ index » next coverage.py v7.6.12, created at 2025-03-20 13:17 -0400
« prev ^ index » next coverage.py v7.6.12, created at 2025-03-20 13:17 -0400
1"""
2----------------------------------------------------------------------------
4 METADATA:
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
14----------------------------------------------------------------------------
16 LAST MODIFIED:
18 2025-03-04 By Jess Mann
20"""
22from __future__ import annotations
24import logging
25from typing import TYPE_CHECKING, Any, Optional, Self, Union
27from paperap.models.abstract.queryset import BaseQuerySet, StandardQuerySet
28from paperap.models.mixins.queryset import HasDocumentCount
30if TYPE_CHECKING:
31 from paperap.models.custom_field.model import CustomField
33logger = logging.getLogger(__name__)
36class CustomFieldQuerySet(StandardQuerySet["CustomField"], HasDocumentCount):
37 """
38 QuerySet for Paperless-ngx custom fields with specialized filtering methods.
39 """
41 def name(self, value: str, *, exact: bool = True, case_insensitive: bool = True) -> Self:
42 """
43 Filter custom fields by name.
45 Args:
46 value: The custom field name to filter by
47 exact: If True, match the exact name, otherwise use contains
48 case_insensitive: If True, ignore case when matching
50 Returns:
51 Filtered CustomFieldQuerySet
53 """
54 return self.filter_field_by_str("name", value, exact=exact, case_insensitive=case_insensitive)
56 def data_type(self, value: str, *, exact: bool = True, case_insensitive: bool = True) -> Self:
57 """
58 Filter custom fields by data type.
60 Args:
61 value: The data type to filter by (e.g., "string", "integer", "boolean", "date")
62 exact: If True, match the exact data type, otherwise use contains
63 case_insensitive: If True, ignore case when matching
65 Returns:
66 Filtered CustomFieldQuerySet
68 """
69 return self.filter_field_by_str("data_type", value, exact=exact, case_insensitive=case_insensitive)
71 def extra_data(self, key: str, value: Any) -> Self:
72 """
73 Filter custom fields by a key-value pair in extra_data.
75 Args:
76 key: The key in extra_data to filter by
77 value: The value to filter by
79 Returns:
80 Filtered CustomFieldQuerySet
82 """
83 filter_key = f"extra_data__{key}"
84 return self.filter(**{filter_key: value})