diff --git a/django/contrib/comments/templatetags/comments.py b/django/contrib/comments/templatetags/comments.py
index 7962a40..52c731c 100644
a
|
b
|
class BaseCommentNode(template.Node):
|
47 | 47 | def lookup_content_type(token, tagname): |
48 | 48 | try: |
49 | 49 | app, model = token.split('.') |
50 | | return ContentType.objects.get(app_label=app, model=model) |
| 50 | return ContentType.objects.get_by_natural_key(app, model) |
51 | 51 | except ValueError: |
52 | 52 | raise template.TemplateSyntaxError("Third argument in %r must be in the format 'app.model'" % tagname) |
53 | 53 | except ContentType.DoesNotExist: |
diff --git a/tests/regressiontests/comment_tests/tests/templatetag_tests.py b/tests/regressiontests/comment_tests/tests/templatetag_tests.py
index 0ead6c2..2ab3273 100644
a
|
b
|
from django.contrib.contenttypes.models import ContentType
|
4 | 4 | from django.template import Template, Context |
5 | 5 | from regressiontests.comment_tests.models import Article, Author |
6 | 6 | from regressiontests.comment_tests.tests import CommentTestCase |
| 7 | from django.db import connection |
| 8 | from django.conf import settings |
7 | 9 | |
8 | 10 | class CommentTemplateTagTests(CommentTestCase): |
9 | 11 | |
… |
… |
class CommentTemplateTagTests(CommentTestCase):
|
100 | 102 | def testRenderCommentListFromObject(self): |
101 | 103 | self.testRenderCommentList("{% render_comment_list for a %}") |
102 | 104 | |
| 105 | class CommentTemplateTagNumQueries(CommentTemplateTagTests): |
| 106 | def setUp(self): |
| 107 | super(CommentTemplateTagNumQueries, self).setUp() |
| 108 | settings.DEBUG = True |
| 109 | |
| 110 | def tearDown(self): |
| 111 | settings.DEBUG = False |
| 112 | super(CommentTemplateTagNumQueries, self).tearDown() |
| 113 | |
| 114 | def renderCommentList(self, tag=None): |
| 115 | connection.queries = [] |
| 116 | t = "{% load comments %}" + (tag or "{% render_comment_list for comment_tests.article a.id %}") |
| 117 | ctx, out = self.render(t, a=Article.objects.get(pk=1)) |
| 118 | return len(connection.queries) |
| 119 | |
| 120 | def testNumberQueries(self): |
| 121 | self.createSomeComments() |
| 122 | |
| 123 | num_queries = self.renderCommentList() |
| 124 | num_queries_2 = self.renderCommentList() |
| 125 | self.assertEquals(num_queries, num_queries_2) |
| 126 | ContentType.objects.__class__._cache = {} |
| 127 | num_queries_3 = self.renderCommentList() |
| 128 | self.assertLess(num_queries_2, num_queries_3) |