Opened 3 years ago

Closed 3 years ago

#33144 closed Bug (invalid)

get_elided_page_range() method doesn't work properly.

Reported by: axinterop Owned by: nobody
Component: Generic views Version: 3.2
Severity: Normal Keywords: paginator, pagination, get_elided_page_range, ListView
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I found that the page number is not passed to the get_elided_page_range method and it uses the default value (1) all the time.

Having, for example, 34 pages, get_elided_page_range will always return 1 2 3 4 … 33 34 range regardless of the current page number.

views.py

class TopicListView(ListView):
    model = Topic
    context_object_name = 'topics'
    template_name = 'topics.html'
    paginate_by = 3

    def get_context_data(self, *, object_list=None, **kwargs):
        context = super().get_context_data(**kwargs)
        context['board'] = self.board
        return context

    def get_queryset(self):
        self.board = get_object_or_404(Board, id=self.kwargs.get('board_id'))
        queryset = self.board.topics.order_by('last_updated').\
            annotate(replies=Count('posts') - 1)
        return queryset

topics.html

...
{% for page_num in paginator.get_elided_page_range %}
    {{ page_num }}
{% endfor %}
...

Change History (1)

comment:1 by Mariusz Felisiak, 3 years ago

Resolution: invalid
Status: newclosed
Summary: 'get_elided_page_range' method doesn't work properlyget_elided_page_range() method doesn't work properly.

Thanks for the report, however it's an issue in your code not in Django itself. get_elided_page_range() is a method not an attribute, and shouldn't be called directly on templates. You can check how it's used in admin, see pagination(). If you're having trouble understanding how Django works, see TicketClosingReasons/UseSupportChannels for ways to get help

Note: See TracTickets for help on using tickets.
Back to Top