26.3.4 Caching Template Variables

Caching properties in our model is a great start to optimizing the Startup detail views, but it only works for unauthenticated users. If you authenticate as a superuser and browse to /startup/simple-robots/, the debug-toolbar will tell you that Django is making 14 queries to display all of the data on this page. That is the same number we had at the beginning of last section and means that the page has not benefitted from our @cached_property decorator, which makes sense: the published_posts() is only called when the visitor doesn’t have the view_future_post permission. As an authenticated superuser, we have this permission, so our page is instead calling startup.blog_posts.all() to render the page.

The problem ...

Get Django Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.