hi,
just use the following.
In views.py import paginator,

from django.core.paginator import Paginator, InvalidPage, EmptyPage
then in your function

bobj = Batch_Criteria_Batch_Instance.objects.all()  # get the objects
or query ur table.
SHOW_CONTENT_LIMIT = 5                                  # set your per
page content limit
paginate_list = Paginator(bobj, SHOW_CONTENT_LIMIT)      # pass your
list of objects to paginator
page_no = int(request.GET.get('page', 1))                       #get
the page request
try:
                contents = paginate_list.page(page_no)       #Gets the contents
according to pages.
except (EmptyPage, InvalidPage):
                contents = paginate_list.page(paginate_list.num_pages)
total_pages_list = range(1,  paginate_list.num_pages + 1)   # total
pages list depending on ur contents in query table.

# then pass the contents and page list to template
return render_to_response('ui/report1.html',
{'bobj':bobj,'contents':contents,'total_pages_list':total_pages_list})

In your template, use to display objects of ur table.

{% for obj in contents.object_list %}
{% endfor %}

To diplay the number of pages u can use,

{% if contents.has_previous %}
  <a href = "?page = {{contents.previous_page_number}}"> Previous </
a>
 {% endif %}
 {% for page_number in total_pages_list %}
        {% ifequal page_number contents.number %}
        <a href="?page={{page_number}}" class="clsActive"
title="Current Page">{{contents.number}}</a>
        {% else %}
        <a id = "currentpage" class = "currentpage" href="?
page={{page_number}}">{{page_number}}</a>
        {% endifequal %}
 {% endfor %}

  {% if contents.has_next %}
   <a href="?page={{contents.next_page_number}}"> Next </a>
  {% endif %}

Lokesh S


On Aug 7, 2:04 pm, Kayode Odeyemi <drey...@gmail.com> wrote:
> This question is related to django-tables. I hope I am allowed to post here.
>
> I will appreciate some help on how to use Django Paginator with
> django-tables. Below is what I have been working with:
>
> report.py
> ------------
>
> import django_tables as tables
> from webapp.models import Transaction
>
> class TransactionReport(tables.ModelTable):
>     #paid = tables.Column(filter='paid')
>     tpin = tables.Column(sortable=False, visible=False)
>     identifier = tables.Column(sortable=False, visible=False)
>     created = tables.Column(sortable=True, visible=True)
>
>     @classmethod
>     def get_reports_paid(self, object, req):
>         return TransactionReport(object, order_by=req)
>
>     class Meta:
>         model = Transaction
>
> views.py
> -----------
>
> @login_required
> def display_reports(request):
>     #data = Transaction.objects.all()
>      logger = logging.getLogger(__name__)
>     dataqs = Transaction.objects.filter(paid="TRUE")
>     req = request.GET.get('sort', 'created')
>
>     tx = TransactionReport().get_reports_paid(dataqs, req) # need to just
> simply pass the paginator parameter to get_reports_paid
>
>     paginator = Paginator(tx, 2)
>
>     # Make sure page request is an int. If not, deliver first page.
>     try:
>         page = int(request.GET.get('page', '1'))
>     except ValueError:
>         page = 1
>
>     # If page request (9999) is out of range, deliver last page of results.
>     try:
>         transaction = paginator.page(page)
>     except (EmptyPage, InvalidPage):
>         transaction = paginator.page(paginator.num_pages)
>
>     return render_to_response('webapp/reports.html', {'table': tx,
> 'paginator': transaction})
>
> In reports.html, the table is displayed but all records are displayed at
> once instead of 2 rows then
> paginated pages.
>
> Any help will be appreciated.
>
> Thanks
>
> --
> Odeyemi 'Kayode O.http://www.sinati.com. t: @charyorde

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to