views:

58

answers:

1

Simply put I want what http://www.reddit.com/ and http://news.ycombinator.com/ have to the left of every link. A numerated link starting with 1 and continuing to the next page by means of pagination.

I really enjoy using generic views and their built-in pagination for Django and it seems to allow me access to these values if I was on page 3 with 2 items per page.

{'MEDIA_URL': ''}
{'LANGUAGES': '<<languages>>',
 'LANGUAGE_BIDI': False,
 'LANGUAGE_CODE': 'en-us'}
{'debug': True, 'sql_queries': '<<sql_queries>>'}
{'messages': [],
 'perms': <django.core.context_processors.PermWrapper object at 0xadedeec>,
 'user': <User: thelizardking>}
{'first_on_page': 5,
 'has_next': True,
 'has_previous': True,
 'hits': 7,
 'is_paginated': True,
 'last_on_page': 6,
 'links_list': [<Link: Funky Town>, <Link: Apple Jax>],
 'next': 4,
 'page': 3,
 'page_obj': <Page 3 of 4>,
 'page_range': [1, 2, 3, 4],
 'pages': 4,
 'paginator': <django.core.paginator.Paginator object at 0xadf914c>,
 'previous': 2,
 'results_per_page': 2}

I know there is an add filter for templates but that's as close as I think I can get and that really doesn't do what I want. Am I going to have to use a custom template filter here or is there something I am not seeing?

+2  A: 

As far as I understand, this number for each item on page is computable from 'first_on_page' and number of current item on the page. Maybe you can get number of current item on the page from cycle data, but if not — you can somewhat easily write an incrementing template tag, possibly with using 'first_on_page' inside.

In particular, `{{ page_obj.start_index|add:forloop.counter|add:-1 }}` works for me (in snapboard's sources, actually).
Wow that works perfectly. Thanks. I am going to have to spend time time trying to figure that one out.
TheLizardKing