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 [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.