diff --git a/django/contrib/comments/templatetags/comments.py b/django/contrib/comments/templatetags/comments.py
index 42691c6..8bc61cd 100644
a
|
b
|
class CommentFormNode(BaseCommentNode):
|
122 | 122 | """Insert a form for the comment model into the context.""" |
123 | 123 | |
124 | 124 | def get_form(self, context): |
125 | | ctype, object_pk = self.get_target_ctype_pk(context) |
126 | | if object_pk: |
127 | | return comments.get_form()(ctype.get_object_for_this_type(pk=object_pk)) |
| 125 | obj = self.get_object(context) |
| 126 | if obj: |
| 127 | return comments.get_form()(obj) |
128 | 128 | else: |
129 | 129 | return None |
130 | 130 | |
| 131 | def get_object(self, context): |
| 132 | if self.object_expr: |
| 133 | try: |
| 134 | return self.object_expr.resolve(context) |
| 135 | except template.VariableDoesNotExist: |
| 136 | return None |
| 137 | else: |
| 138 | object_pk = self.object_pk_expr.resolve(context, |
| 139 | ignore_failures=True) |
| 140 | return self.ctype.get_object_for_this_type(pk=object_pk) |
| 141 | |
131 | 142 | def render(self, context): |
132 | 143 | context[self.as_varname] = self.get_form(context) |
133 | 144 | return '' |
diff --git a/tests/regressiontests/comment_tests/tests/templatetag_tests.py b/tests/regressiontests/comment_tests/tests/templatetag_tests.py
index 4c90d9d..0ead6c2 100644
a
|
b
|
class CommentTemplateTagTests(CommentTestCase):
|
40 | 40 | def testRenderCommentFormFromObject(self): |
41 | 41 | self.testRenderCommentForm("{% render_comment_form for a %}") |
42 | 42 | |
| 43 | def testRenderCommentFormFromObjectWithQueryCount(self): |
| 44 | def test(): |
| 45 | self.testRenderCommentFormFromObject() |
| 46 | self.assertNumQueries(1, test) |
| 47 | |
43 | 48 | def testGetCommentCount(self, tag=None): |
44 | 49 | self.createSomeComments() |
45 | 50 | t = "{% load comments %}" + (tag or "{% get_comment_count for comment_tests.article a.id as cc %}") + "{{ cc }}" |