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?
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.
精彩评论