From 77e97e8bd924e7f31f9b33e03a11fd63f4b24efe Mon Sep 17 00:00:00 2001 From: Simon Fransson Date: Tue, 10 Feb 2015 17:59:09 +0100 Subject: [PATCH] Using ContentType.objects.get_for_id rather than accessing for search_result.content_type, for caching benefits. --- src/watson/templatetags/watson.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/watson/templatetags/watson.py b/src/watson/templatetags/watson.py index 1a9c587..b63ed11 100644 --- a/src/watson/templatetags/watson.py +++ b/src/watson/templatetags/watson.py @@ -3,6 +3,7 @@ from __future__ import unicode_literals from django import template +from django.contrib.contenttypes.models import ContentType register = template.Library() @@ -29,9 +30,11 @@ def search_results(context, search_results): @register.simple_tag(takes_context=True) def search_result_item(context, search_result): obj = search_result.object + content_type = ContentType.objects.get_for_id(search_result.content_type_id) + params = { - "app_label": search_result.content_type.app_label, - "model_name": search_result.content_type.model, + "app_label": content_type.app_label, + "model_name": content_type.model, } # Render the template. context.push()