Using ContentType.objects.get_for_id rather than accessing for search_result.content_type, for caching benefits.

This commit is contained in:
Simon Fransson 2015-02-10 17:59:09 +01:00
parent 52794ac35d
commit 77e97e8bd9

View file

@ -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()