Django Bootstrap Pagination Helper

I Just writing simple script for creating simple pagination with django and bootstrap.
To use these, what you need to do just add the middleware class to your settings.py, within you views just pass your queryset to the paginate function, then just include the html to you template.

Here is the usage example:

# views.py
class MemberView(TemplateView):
    template_name = 'persons/list.html'
    
    def get(self, request, *args, **kwargs):
        person_list = Person.objects.all()
        members = paginate(request=request, queryset=person_list, limit=30)

        context = self.get_context()
        context.update({
            'members': members
        })
        return super(MemberView, self).render_to_response(context)

# list.html
{% include 'paging.html' with paginator=members %}

NB: I assumed you are using twitter bootstrap on your project.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s