How to create a Paginator for Class Based Views?

I have a requirement for my web application, and that's to create employees ListViews with pagination by last name.

The class to list is like follows:

class Person(models.Model):
    first_name = models.CharField(blank=True)
    last_name = models.CharField(blank=True)
    # etc.

I have a ListView with a Mixin as well:

class PersonMixin(object):
    def get_queryset(self):
        return Person.objects.order_by('last_name', 'first_name')


class PersonListView(PersonMixin, ListView):
    paginate_by = settings.ARCHIVE_PAGE_SIZE
    template_name = 'profile_list.html'
    paginator_class = FamilyNamePaginator

And finally, I've overriden the Paginator class.

class FamilyNamePaginator(Paginator):
    def page(self, number):
        page = super(FamilyNamePaginator, self).page(number)
        return page

But obviously, the behaviour for the moment is too basic. I need to substitute, for example, "page 1 of 6" by "A ... M P Z", being those the last name initials. I have not found any documentation pointing out how to customize the Paginator class, can anyone point out where should I start digging here?

Thanks in advance :-)

Answers


As @daniel-roseman said in his comment, it's not pagination. Instead, try creating a, say, AlphabetPersonView, with the accompanying URL, and then a template tag which would be inserted wherever this navigation element needs to go.


Need Your Help

Android Studio, Rendering problems

android android-layout widget

I've just installed Android Studio but when i started it tells me:

Publish fails in Visual Studio 2015 with message: "The 'prepare' script failed with status code -1073741819."

visual-studio-2015 gulp asp.net-core publish dnx

When publishing my asp.net 5 project, the output directory stays empty and I get the error: "The 'prepare' script failed with status code -1073741819."