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
« prev ^ index » next coverage.py v7.6.12, created at 2025-03-18 12:26 -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, name: str, *, exact: bool = True) -> Self:
42 """
43 Filter custom fields by name.
45 Args:
46 name: The custom field name to filter by
47 exact: If True, match the exact name, otherwise use contains
49 Returns:
50 Filtered CustomFieldQuerySet
52 """
53 if exact:
54 return self.filter(name=name)
55 return self.filter(name__contains=name)
57 def data_type(self, data_type: str) -> Self:
58 """
59 Filter custom fields by data type.
61 Args:
62 data_type: The data type to filter by (e.g., "string", "integer", "boolean", "date")
64 Returns:
65 Filtered CustomFieldQuerySet
67 """
68 return self.filter(data_type=data_type)