[EMAIL PROTECTED] wrote:
> Hey,
> 
> I was just wondering if someone could help me out. I want to paginate
> some views, but they are not generic. This is one of the views I want
> to paginate:
> 
> def category_list(request):
>       categories = Category.objects.order_by('name')
> 
>       return shortcuts.render_to_response("blog/category_list.html",
> dict(categories = categories))
> 
> How would I go about paginating that?

Like this:

     from django.core.paginator import ObjectPaginator, InvalidPage

     def category_list(request):
       paginator = ObjectPaginator(Category.objects.order_by('name'), 50)
       try:
         page = request.GET.get('page', 1)
         categories = paginator.get_page(page - 1)
       except InvalidPage:
         categories = []
       return render_to_response('template.html', {
         'paginator': paginator,
         'page': page,
         'categories': categories,
       }, context_instance=RequestContext(request))

--~--~---------~--~----~------------~-------~--~----~
 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?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to