1

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

sogeking
  • 1,216
  • 2
  • 14
  • 45
  • http://stackoverflow.com/questions/5907575/how-do-i-use-pagination-with-django-class-based-generic-listviews – karthikr Mar 12 '14 at 14:23
  • Thanks karthikr, but that's about how to **use** pagination. I think I need to create a custom Paginator class instead. – sogeking Mar 12 '14 at 14:46
  • 2
    This isn't really pagination at all, though. This is about separate links to individual pages keyed by initial letter, which is a completely different thing. – Daniel Roseman Mar 12 '14 at 16:18
  • Well, in my mindset it really looks like pagination. But maybe you're right :-) – sogeking Mar 14 '14 at 09:08

1 Answers1

1

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.

Berislav Lopac
  • 16,656
  • 6
  • 71
  • 80