paperap.models.document.queryset module
METADATA:
- File: queryset.py
Project: paperap
- Created: 2025-03-04
Version: 0.0.10
Author: Jess Mann Email: jess@jmann.me
Copyright (c) 2025 Jess Mann
LAST MODIFIED:
2025-03-04 By Jess Mann
- class paperap.models.document.queryset.CustomFieldQuery(field, operation, value)[source]
Bases:
NamedTuple
- class paperap.models.document.queryset.DocumentNoteQuerySet(resource, filters=None, _cache=None, _fetch_all=False, _next_url=None, _last_response=None, _iter=None, _urls_fetched=None)[source]
Bases:
StandardQuerySet[DocumentNote]- Parameters:
resource (BaseResource[_Model, Self])
filters (dict[str, Any] | None)
_cache (list[_Model] | None)
_fetch_all (bool)
_next_url (str | None)
_last_response (ClientResponse)
_iter (Iterator[_Model] | None)
_urls_fetched (list[str] | None)
- class paperap.models.document.queryset.DocumentQuerySet(resource, filters=None, _cache=None, _fetch_all=False, _next_url=None, _last_response=None, _iter=None, _urls_fetched=None)[source]
Bases:
StandardQuerySet[Document],HasOwnerQuerySet for Paperless-ngx documents with specialized filtering methods.
Examples
>>> # Search for documents >>> docs = client.documents().search("invoice") >>> for doc in docs: ... print(doc.title)
>>> # Find documents similar to a specific document >>> similar_docs = client.documents().more_like(42) >>> for doc in similar_docs: ... print(doc.title)
- Parameters:
resource (BaseResource[_Model, Self])
filters (dict[str, Any] | None)
_cache (list[_Model] | None)
_fetch_all (bool)
_next_url (str | None)
_last_response (ClientResponse)
_iter (Iterator[_Model] | None)
_urls_fetched (list[str] | None)
- resource: DocumentResource
- tag_name(tag_name, *, exact=True, case_insensitive=True)[source]
Filter documents that have a tag with the specified name.
- search(query)[source]
Search for documents using a query string.
- Parameters:
query (
str) – The search query.- Return type:
- Returns:
A queryset with the search results.
Examples
>>> docs = client.documents().search("invoice") >>> for doc in docs: ... print(doc.title)
- more_like(document_id)[source]
Find documents similar to the specified document.
- Parameters:
document_id (
int) – The ID of the document to find similar documents for.- Return type:
- Returns:
A queryset with similar documents.
Examples
>>> similar_docs = client.documents().more_like(42) >>> for doc in similar_docs: ... print(doc.title)
- correspondent(value=None, *, exact=True, case_insensitive=True, **kwargs)[source]
Filter documents by correspondent.
Any number of filter arguments can be provided, but at least one must be specified.
- Parameters:
- Return type:
Self- Returns:
Filtered DocumentQuerySet
- Raises:
ValueError – If no valid filters are provided
Examples
# Filter by ID client.documents().all().correspondent(1) client.documents().all().correspondent(id=1)
# Filter by name client.documents().all().correspondent(“John Doe”) client.documents().all().correspondent(name=”John Doe”)
# Filter by name (exact match) client.documents().all().correspondent(“John Doe”, exact=True) client.documents().all().correspondent(name=”John Doe”, exact=True)
# Filter by slug client.documents().all().correspondent(slug=”john-doe”)
# Filter by ID and name client.documents().all().correspondent(1, name=”John Doe”) client.documents().all().correspondent(id=1, name=”John Doe”) client.documents().all().correspondent(“John Doe”, id=1)
- Parameters:
case_insensitive (
bool)
- correspondent_id(correspondent_id)[source]
Filter documents by correspondent ID.
- Parameters:
correspondent_id (
int) – The correspondent ID to filter by- Return type:
Self- Returns:
Filtered DocumentQuerySet
- correspondent_name(name, *, exact=True, case_insensitive=True)[source]
Filter documents by correspondent name.
- correspondent_slug(slug, *, exact=True, case_insensitive=True)[source]
Filter documents by correspondent slug.
- document_type(value=None, *, exact=True, case_insensitive=True, **kwargs)[source]
Filter documents by document type.
Any number of filter arguments can be provided, but at least one must be specified.
- Parameters:
- Return type:
Self- Returns:
Filtered DocumentQuerySet
- Raises:
ValueError – If no valid filters are provided
Examples
# Filter by ID client.documents().all().document_type(1) client.documents().all().document_type(id=1)
# Filter by name client.documents().all().document_type(“Invoice”) client.documents().all().document_type(name=”Invoice”)
# Filter by name (exact match) client.documents().all().document_type(“Invoice”, exact=True) client.documents().all().document_type(name=”Invoice”, exact=True)
# Filter by ID and name client.documents().all().document_type(1, name=”Invoice”) client.documents().all().document_type(id=1, name=”Invoice”) client.documents().all().document_type(“Invoice”, id=1)
- Parameters:
case_insensitive (
bool)
- document_type_id(document_type_id)[source]
Filter documents by document type ID.
- Parameters:
document_type_id (
int) – The document type ID to filter by- Return type:
Self- Returns:
Filtered DocumentQuerySet
- document_type_name(name, *, exact=True, case_insensitive=True)[source]
Filter documents by document type name.
- storage_path(value=None, *, exact=True, case_insensitive=True, **kwargs)[source]
Filter documents by storage path.
Any number of filter arguments can be provided, but at least one must be specified.
- Parameters:
- Return type:
Self- Returns:
Filtered DocumentQuerySet
- Raises:
ValueError – If no valid filters are provided
Examples
# Filter by ID client.documents().all().storage_path(1) client.documents().all().storage_path(id=1)
# Filter by name client.documents().all().storage_path(“Invoices”) client.documents().all().storage_path(name=”Invoices”)
# Filter by name (exact match) client.documents().all().storage_path(“Invoices”, exact=True) client.documents().all().storage_path(name=”Invoices”, exact=True)
# Filter by ID and name client.documents().all().storage_path(1, name=”Invoices”) client.documents().all().storage_path(id=1, name=”Invoices”) client.documents().all().storage_path(“Invoices”, id=1)
- Parameters:
case_insensitive (
bool)
- storage_path_id(storage_path_id)[source]
Filter documents by storage path ID.
- Parameters:
storage_path_id (
int) – The storage path ID to filter by- Return type:
Self- Returns:
Filtered DocumentQuerySet
- storage_path_name(name, *, exact=True, case_insensitive=True)[source]
Filter documents by storage path name.
- content(text)[source]
Filter documents whose content contains the specified text.
- Parameters:
text (
str) – The text to search for in document content- Return type:
Self- Returns:
Filtered DocumentQuerySet
- added_after(date_str)[source]
Filter documents added after the specified date.
- Parameters:
date_str (
str) – ISO format date string (YYYY-MM-DD)- Return type:
Self- Returns:
Filtered DocumentQuerySet
- added_before(date_str)[source]
Filter documents added before the specified date.
- Parameters:
date_str (
str) – ISO format date string (YYYY-MM-DD)- Return type:
Self- Returns:
Filtered DocumentQuerySet
- asn(value, *, exact=True, case_insensitive=True)[source]
Filter documents by archive serial number.
- original_filename(name, *, exact=True, case_insensitive=True)[source]
Filter documents by original file name.
- user_can_change(value)[source]
Filter documents by user change permission.
- Parameters:
value (
bool) – True to filter documents the user can change- Return type:
Self- Returns:
Filtered DocumentQuerySet
- custom_field_fullsearch(value, *, case_insensitive=True)[source]
Filter documents by searching through both custom field name and value.
- custom_field(field, value, *, exact=False, case_insensitive=True)[source]
Filter documents by custom field.
- has_custom_field_id(pk, *, exact=False)[source]
Filter documents that have a custom field with the specified ID(s).
- custom_field_range(field, start, end)[source]
Filter documents with a custom field value within a specified range.
- custom_field_exact(field, value)[source]
Filter documents with a custom field value that matches exactly.
- custom_field_in(field, values)[source]
Filter documents with a custom field value in a list of values.
- custom_field_isnull(field)[source]
Filter documents with a custom field that is null or empty.
- Parameters:
field (
str) – The name of the custom field- Return type:
Self- Returns:
Filtered DocumentQuerySet
- custom_field_exists(field, exists=True)[source]
Filter documents based on the existence of a custom field.
- custom_field_contains(field, values)[source]
Filter documents with a custom field that contains all specified values.
- notes(text)[source]
Filter documents whose notes contain the specified text.
- Parameters:
text (
str) – The text to search for in document notes- Return type:
Self- Returns:
Filtered DocumentQuerySet
- delete()[source]
Delete all documents in the current queryset.
- Return type:
TypeAliasType- Returns:
Self for method chaining
Examples
>>> # Delete all documents with "invoice" in title >>> client.documents().title("invoice", exact=False).delete()
- reprocess()[source]
Reprocess all documents in the current queryset.
- Return type:
TypeAliasType- Returns:
Self for method chaining
Examples
>>> # Reprocess documents added in the last week >>> from datetime import datetime, timedelta >>> week_ago = datetime.now() - timedelta(days=7) >>> client.documents().added_after(week_ago.strftime("%Y-%m-%d")).reprocess()
- merge(metadata_document_id=None, delete_originals=False)[source]
Merge all documents in the current queryset.
- Parameters:
- Return type:
- Returns:
True if submitting the merge succeeded, False if there are no ids to merge
- Raises:
BadResponseError – If the merge action returns an unexpected response
APIError – If the merge action fails
Examples
>>> # Merge all documents with tag "merge_me" >>> client.documents().tag_name("merge_me").merge(delete_originals=True)
- rotate(degrees)[source]
Rotate all documents in the current queryset.
- Parameters:
degrees (
int) – Degrees to rotate (must be 90, 180, or 270)- Return type:
TypeAliasType- Returns:
Self for method chaining
Examples
>>> # Rotate all documents with "sideways" in title by 90 degrees >>> client.documents().title("sideways", exact=False).rotate(90)
- update(*, correspondent=None, document_type=None, storage_path=None, owner=None)[source]
Perform bulk updates on all documents in the current queryset.
This method allows for multiple update operations in a single call.
- Parameters:
correspondent (
Correspondent|int|None) – Set correspondent for all documentsdocument_type (
DocumentType|int|None) – Set document type for all documentsstorage_path (
StoragePath|int|None) – Set storage path for all documents
- Return type:
Self- Returns:
Self for method chaining
- modify_custom_fields(add_custom_fields=None, remove_custom_fields=None)[source]
Modify custom fields on all documents in the current queryset.
- Parameters:
- Return type:
Self- Returns:
Self for method chaining
Examples
>>> # Add a custom field to documents with "invoice" in title >>> client.documents().title("invoice", exact=False).modify_custom_fields( ... add_custom_fields={5: "Processed"} ... )
- modify_tags(add_tags=None, remove_tags=None)[source]
Modify tags on all documents in the current queryset.
- Parameters:
- Return type:
Self- Returns:
Self for method chaining
Examples
>>> # Add tag 3 and remove tag 4 from all documents with "invoice" in title >>> client.documents().title("invoice", exact=False).modify_tags( ... add_tags=[3], remove_tags=[4] ... )
- add_tag(tag_id)[source]
Add a tag to all documents in the current queryset.
- Parameters:
tag_id (
int) – Tag ID to add- Return type:
Self- Returns:
Self for method chaining
Examples
>>> # Add tag 3 to all documents with "invoice" in title >>> client.documents().title("invoice", exact=False).add_tag(3)
- filters: dict[str, Any]
- remove_tag(tag_id)[source]
Remove a tag from all documents in the current queryset.
- Parameters:
tag_id (
int) – Tag ID to remove- Return type:
Self- Returns:
Self for method chaining
Examples
>>> # Remove tag 4 from all documents with "invoice" in title >>> client.documents().title("invoice", exact=False).remove_tag(4)
- set_permissions(permissions=None, owner_id=None, merge=False)[source]
Set permissions for all documents in the current queryset.
- Parameters:
- Return type:
Self- Returns:
Self for method chaining
Examples
>>> # Set owner to user 2 for all documents with "invoice" in title >>> client.documents().title("invoice", exact=False).set_permissions(owner_id=2)