django-sqlpaginator

Does pagination and ordering using raw SQL on a Model
Download

django-sqlpaginator Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Other/Proprietary Li...
  • Price:
  • FREE
  • Publisher Name:
  • Bulkan Evcimen
  • Publisher web site:
  • https://github.com/bulkan/

django-sqlpaginator Tags


django-sqlpaginator Description

django-sqlpaginator is a Django app that does pagination and ordering using raw SQL on a Model.InstallationTo install from pypipip install django-sqlpaginatorTo get the latest (and possibly non stable version) from gitpip install git+git://github.com/bulkan/django-sqlpaginator.gitYou also need to install sqlparserpip install git+git://github.com/andialbrecht/sqlparse.gitIn settings.py INSTALLED_APPS = ( ... 'sqlpaginator', ... )Thats it !!UsagePretty much same as django.core.pagination.PaginatorIf you have the following models class Album(models.Model): albumid = models.IntegerField(primary_key=True, db_column=u'AlbumId') title = models.TextField(db_column=u'Title') artistid = models.IntegerField(db_column=u'ArtistId') class Artist(models.Model): artistid = models.IntegerField(primary_key=True, db_column=u'ArtistId') name = models.TextField(db_column=u'Name', blank=True) and you want to paginate on Albums, then inside a view; from sqlpaginator.paginator import SqlPaginator from models import Album def get_albums(request, page=1): sql = "select * from %s" % Album._meta.db_table paginator = SqlPaginator(sql, Album, page=page, order_by='title') try: albums = paginator.page(page) except PageNotAnInteger: # If page is not an integer, deliver first page. albums = paginator.page(1) except EmptyPage: # If page is out of range (e.g. 9999), deliver last page of results. albums = paginator.page(paginator.num_pages) return render_to_response('albums_list.html', {'albums': albums})In the template albums_list.html {% for album in albums %} {# Each "album" is a Album model object. #} {{ album.title|upper }}< br / > {% endfor %} < div class="pagination" > < span class="step-links" > {% if albums.has_previous %} < a href="?page={{ albums.previous_page_number }}" >previous< /a > {% endif %} < span class="current" > Page {{ albums.number }} of {{ albums.paginator.num_pages }}. < /span > {% if albums.has_next %} < a href="?page={{ albums.next_page_number }}" >next< /a > {% endif %} < /span > < /div >Product's homepage


django-sqlpaginator Related Software