Вопрос

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 :-)

Это было полезно?

Решение

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top