(django-tables) paginator question

44 views
Skip to first unread message

Robert

unread,
Sep 30, 2008, 9:22:40 AM9/30/08
to Django Apps
[Seems like google has not published my previous post (also fixed the
prefix). Sorry if this post appears twice.]

Hello,

First of all, thanks for great django-tables project.

Is there any way so I can get this working with django-pagination ?

http://code.google.com/p/django-pagination

Im a total noob in django.

In my views.py I've defined the OfferTable class:

table = OfferTable(
queryset,
order_by=request.GET.get('sort', 'date_added'),
)

table is sent to template via extra_context (using generic view)

By u sing {% autopaginate %} and the rest of required tags I got page
numbers at the bottom
of the table.. but from my 27 offers (just for test) even if I
paginate by 10 I get all 27 offers on every page.

Looks like OfferTable ignores the pagination (which I'm 100% sure).

from README:
table.paginate(QuerySetPaginator, page=1, 10, padding=2)
gives "non-keyword arg after keyword arg"

I'm using table.rows for {% autopaginate %} tag.

Please help,

Thanks.
Robert

Michael Elsdörfer

unread,
Oct 2, 2008, 8:36:15 AM10/2/08
to Django Apps
> [Seems like google has not published my previous post (also fixed the
> prefix). Sorry if this post appears twice.]

I am moderating the list for now, to get people to use the right
prefix in their message subjects. The idea is that app authors can
configure their mail filters so that they receive only those messages
relevant to them. Speaking of which, you should use "(tables)", rather
than "(django-tables)".

Also, sorry for the delay - I am not using django-pagination, and had
to investigate first. The problem is that {% autopaginate %} tries to
replace the variable passed in with a paginated version - in your case
this fails, since "table.rows" is not a "simple" variable: django-
pagination does not handle the attribute notation.

While you could potentially call this a bug, solving it is between
hard and impossible, since the attribute may be readonly. In fact,
table.rows **is** readonly. I suppose though that django-pagination
should probably provide an option to place the paginated version in a
new context variable.

For now, you can solve this be using a temporary variable yourself:

return render_to_response(template.html, {'table': table,
'rows': table.rows})

Template:

{% autopaginate rows %}
{% for row in rows %}
....
{% endfor %}


> from README:
> table.paginate(QuerySetPaginator, page=1, 10, padding=2)
> gives "non-keyword arg after keyword arg"

Oh. That's an error in the readme. It should of course be:

table.paginate(QuerySetPaginator, 10, page=1, padding=2)

I fixed it in bzr. Note however that this is completely different
approach than django-pagination. You probably want to use either of
the two, note both.

Michael

Robert

unread,
Oct 2, 2008, 3:25:55 PM10/2/08
to Django Apps
> > from README:
> > table.paginate(QuerySetPaginator, page=1, 10, padding=2)
> > gives "non-keyword arg after keyword arg"
>
> Oh. That's an error in the readme. It should of course be:
>
>      table.paginate(QuerySetPaginator, 10, page=1, padding=2)

Thank you for your answer Michael.
Sorry for the wrong subject prefix. I realized that later, but sending
3 posts at the same time
would not be ok too :-(

Back to pagination...
The solution you have provided me with works great.

I am learning python & Django, and I would not find out that.
I'm reading lots of code a lot and hope to get pythonic skills soon.

As for django-tables, when using built-in paginate as stated above I
am getting:
"Exception Value: __init__() got an unexpected keyword argument
'padding'"

Though I am using django-paginator, and do not need to use
table.paginate()
I think it's worth mentioning. (Assuming I'm not screwing anything..
which causes this error).

Thanks!
Robert

Michael Elsdörfer

unread,
Oct 2, 2008, 8:18:58 PM10/2/08
to Django Apps
> As for django-tables, when using built-in paginate as stated above I
> am getting:
> "Exception Value: __init__() got an unexpected keyword argument
> 'padding'"

Hm, yes. The default paginator doesn't support this argument, however,
a custom digg-like paginator class I wrote does. You are right though
that this is very confusing. I'll change it - thanks for the heads up.

Michael
Reply all
Reply to author
Forward
0 new messages