mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-10-04 15:20:30 +00:00
Fix: use version page_count for versioned document (#14280)
This commit is contained in:
@@ -1079,6 +1079,16 @@ class DocumentSerializer(
|
||||
)
|
||||
|
||||
def get_page_count(self, obj) -> int | None:
|
||||
# Like content versions get their own page count from the newest version,
|
||||
# use the prefetched versions cache to avoid an extra query
|
||||
prefetched_cache = getattr(obj, "_prefetched_objects_cache", None)
|
||||
prefetched_versions = (
|
||||
prefetched_cache.get("versions")
|
||||
if isinstance(prefetched_cache, dict)
|
||||
else None
|
||||
)
|
||||
if obj.root_document_id is None and prefetched_versions:
|
||||
return sort_versions_newest_first(prefetched_versions)[0].page_count
|
||||
return obj.page_count
|
||||
|
||||
@extend_schema_field(DuplicateDocumentSummarySerializer(many=True))
|
||||
|
||||
Reference in New Issue
Block a user