[GH-ISSUE #72] Document view random page order #55

Closed
opened 2026-02-25 21:31:06 +03:00 by kerem · 1 comment
Owner

Originally created by @defaultroute-eu on GitHub (Aug 17, 2020).
Original GitHub issue: https://github.com/ciur/papermerge/issues/72

When importing a scanned multi-page document I have the pages displayed in random order when viewing the document:
grafik

I fixed this issue in my instance (papermerge running in containers with a postgres db) by adding an ordered_by call to the queryset in github.com/ciur/papermerge@815079151e/papermerge/core/views/documents.py (L48) like this:

        return render(
            request,
            'admin/document.html',
            {
                'pages': doc.pages.all().order_by('number'),
                'document': doc
            }
        )

Since I found several usages of pages.all() on Document objects, another possibility would be adding a Meta class to Page like this (but I don't know, if this would break something):

    class Meta:
        ordering = ['number']

What do you think?

Originally created by @defaultroute-eu on GitHub (Aug 17, 2020). Original GitHub issue: https://github.com/ciur/papermerge/issues/72 When importing a scanned multi-page document I have the pages displayed in random order when viewing the document: ![grafik](https://user-images.githubusercontent.com/29011185/90375787-b757c700-e075-11ea-8fe4-5117b3194e2e.png) I fixed this issue in my instance (papermerge running in containers with a postgres db) by adding an ordered_by call to the queryset in https://github.com/ciur/papermerge/blob/815079151ec388fde5d6a572d7bcdbcf0decfa06/papermerge/core/views/documents.py#L48 like this: ```python return render( request, 'admin/document.html', { 'pages': doc.pages.all().order_by('number'), 'document': doc } ) ``` Since I found several usages of pages.all() on Document objects, another possibility would be adding a Meta class to [Page ](https://github.com/ciur/papermerge/blob/815079151ec388fde5d6a572d7bcdbcf0decfa06/papermerge/core/models/page.py#L21 )like this (but I don't know, if this would break something): ```python class Meta: ordering = ['number'] ``` What do you think?
kerem 2026-02-25 21:31:06 +03:00
Author
Owner

@ciur commented on GitHub (Aug 17, 2020):

Fantastic!

@defaultroute-eu, if submit a PR with that change (adding ordering to Page's metaclass) I will accept it right away.

Unfortunately there are no tests for that feature/part of code. But don't worry, if you do the change, I will add a UT (unit test) for that behaviour.

Thank you for your contribution!

<!-- gh-comment-id:674758346 --> @ciur commented on GitHub (Aug 17, 2020): Fantastic! @defaultroute-eu, if submit a PR with that change (adding ordering to Page's metaclass) I will accept it right away. Unfortunately there are no tests for that feature/part of code. But don't worry, if you do the change, I will add a UT (unit test) for that behaviour. Thank you for your contribution!
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/papermerge#55
No description provided.