paperap.models.custom_field.model module
Module for working with custom fields in Paperless-NgX.
This module provides the CustomField model class for interacting with custom fields in a Paperless-NgX instance. Custom fields allow users to add additional metadata to documents beyond the standard fields provided by Paperless-NgX.
- class paperap.models.custom_field.model.CustomField(**data)[source]
Bases:
StandardModel
Represents a custom field in Paperless-NgX.
Custom fields allow adding additional metadata to documents beyond the standard fields provided by Paperless-NgX. Each custom field has a name, data type, and can be applied to multiple documents.
- name
The display name of the custom field.
- data_type
The data type of the custom field (string, integer, boolean, etc.).
- extra_data
Additional data associated with the custom field.
- document_count
Number of documents using this custom field.
Examples
>>> # Create a new custom field >>> date_field = client.custom_fields.create( ... name="Due Date", ... data_type="date" ... ) >>> >>> # Set custom field on a document >>> doc = client.documents.get(123) >>> doc.custom_fields = {date_field.id: "2023-04-15"} >>> doc.save()
- Parameters:
data (
Any
)
- name: str
- data_type: CustomFieldTypes | None
- classmethod validate_data_type(v)[source]
Validate the data_type field.
Converts string values to the appropriate CustomFieldTypes enum value and validates that the data type is supported.
- Parameters:
v (
Any
) – The value to validate, can be a string, CustomFieldTypes enum, or None.- Return type:
- Returns:
The validated CustomFieldTypes enum value or None.
- Raises:
ValueError – If the value is not a valid data type.
- extra_data: dict[str, Any]
- document_count: int
- model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'allow', 'populate_by_name': True, 'use_enum_values': True, 'validate_assignment': True, 'validate_default': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class Meta(model)[source]
Bases:
Meta
Metadata for the CustomField model.
Defines read-only fields and other metadata for the CustomField model.
- read_only_fields
Set of field names that should not be modified by the client.
- Parameters:
model (type[_Self])
- read_only_fields: ClassVar[set[str]] = {'id', 'slug'}
- blacklist_filtering_params: ClassVar[set[str]] = {}
- field_map: dict[str, str] = {}
- filtering_disabled: ClassVar[set[str]] = {}
- filtering_fields: ClassVar[set[str]] = {'_resource', 'data_type', 'document_count', 'extra_data', 'id', 'name'}
- supported_filtering_params: ClassVar[set[str]] = {'id', 'id__in', 'limit'}
- model: type[_Self]
- name: str
- property documents: DocumentQuerySet
Get documents that have this custom field.
- Returns:
A DocumentQuerySet containing all documents that have this custom field.
Examples
>>> # Get all documents with a specific custom field >>> field = client.custom_fields.get(5) >>> for doc in field.documents: ... print(doc.title)
- model_post_init(context: Any, /) None
We need to both initialize private attributes and call the user-defined model_post_init method.
- id: int