#2351: MySQL syntax error on object.all().count(), when called from template
------------------------------+---------------------------------------------
Reporter: gumuz | Owner: adrian
Type: defect | Status: new
Priority: normal | Milestone:
Component: Database wrapper | Version:
Severity: normal | Keywords:
------------------------------+---------------------------------------------
I have a blogpost model which is referenced by a Comment class. Thus, the
Blogpost model has a comment_set attribute.
I gave the Blogpost model a method like this:
{{{
def comments(self):
return self.comment_set.all()
}}}
When i access it from the shell and use the .count() method on the
!QuerySet, everything is fine:
{{{
>>> from devlog.weblog.models import Post
>>> p = Post.objects.all()[4]
>>> p.comments()
[<Comment: gumuz - 2006-07-12 07:10:30>, <Comment: gumuz - 2006-07-12
07:09:56>]
>>> p.comments().count()
2L
}}}
When i do the same from my template:
{{{
{{ object.comments.count }}
}}}
I get the following error:
{{{
Exception Type: ProgrammingError
Exception Value: (1064, "You have an error in your SQL syntax;
check the manual that corresponds to your MySQL server version for the
right syntax to use near 'count,1' at line 1")
Exception Location: /usr/lib/python2.4/site-
packages/MySQLdb/connections.py in defaulterrorhandler, line 33
}}}
The length-filter works fine though:
{{{
{{ object.comments|length }}
}}}
--
Ticket URL: <http://code.djangoproject.com/ticket/2351>
Django <http://code.djangoproject.org/>
The web framework for perfectionists with deadlines.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-updates
-~----------~----~----~----~------~----~------~--~---