Django paging object has issues with Postgresql QuerySets

Posted by pivotal on Stack Overflow See other posts from Stack Overflow or by pivotal
Published on 2011-02-02T00:29:50Z Indexed on 2011/02/02 15:25 UTC
Read the original article Hit count: 228

I have some django code that runs fine on a SQLite database or on a MySQL database, but it runs into problems with Postgres, and it's making me crazy that no one has has this issue before. I think it may also be related to the way querysets are evaluated by the pager.

In a view I have:

def index(request, page=1):
    latest_posts = Post.objects.all().order_by('-pub_date')
    paginator = Paginator(latest_posts, 5)
    try:
        posts = paginator.page(page)
    except (EmptyPage, InvalidPage):
        posts = paginator.page(paginator.num_pages)
    return render_to_response('blog/index.html', {'posts' : posts})

And inside the template:

{% for post in posts.object_list %}
    {# some rendering jazz #}
{% endfor %}

This works fine with SQLite, but Postgres gives me:

Caught TypeError while rendering: 'NoneType' object is not callable

To further complicate things, when I switch the Queryset call to:

latest_posts = Post.objects.all()

Everything works great. I've tried re-reading the documentation, but found nothing, although I admit I'm a bit clouded by frustration at this point. What am I missing?

Thanks in advance.

© Stack Overflow or respective owner

Related posts about python

Related posts about django