On 3/24/06, Stephen <[EMAIL PROTECTED]> wrote:
>
> Hello,
>
> I've just started looking at Django, it's certainly looking like a very
> good choice for the sort of projects I'll be doing in the near future.
>
>
> Just now I've been looking at pagination and have a question:
>
> I'm using the generic view "list_detail" to view a list of results.  I
> want to use pagination to restrict the number of items on a page.  To
> do this I've added a "paginate_by" value to the info_dict dictionary in
> my urls.py file.  This results in my results being paginated correctly,
> and the additional context parameters are available in my template.  I
> can use these to show how many hits there were and how many pages of
> results etc there are.  My problem comes with trying to show a numbered
> link to each page of results (like google does at the bottom of its
> results page).  I thought this would be straightforward - just do a
> loop - but as far as I can see the {% for %} tag can only iterate over
> an array, and the "pages" context property is a number.  What is the
> right way to go about looping from N to N+M in a template ?  My feeling
> is that looping over a list is the nicest way, but then I can't get the
> pagination to work like I want!  Apologies if I'm missing something
> really obvious!
>
> In the course of trying to figure this out I tinkered around with the
> list_detail.py file and tried adding extra context parameters (e.g.
> 'page_list':range(1, pages+1, 1) ).  These never showed up in my
> templates though - are there specific steps to take in order to make
> changes to the django source files be noticed by the server (I'm using
> the test server that comes with Django)?
>
> Thanks in advance for any help,
>
> Stephen.
>
>

One way I think is just like what you do: create a extra_context.

The other way is create a custom tag to create a list. Someone has
submit this patch before. http://code.djangoproject.com/ticket/1162

Or you can use a custom tag written by me to calculate the list in
template: expr tag

http://groups.google.com/group/django-users/browse_thread/thread/6c1c162e7dd5d0d8/ce3aa7e2e3d48ae1?lnk=st&q=an+expression+tag&rnum=3#ce3aa7e2e3d48ae1

{% expr range(pages) as page_number %}
{% for i in page_number %}
...
{% endfor %}
--
I like python!
My Blog: http://www.donews.net/limodou
NewEdit Maillist: http://groups.google.com/group/NewEdit

--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

Reply via email to