Opened 13 years ago
Closed 13 years ago
#16889 closed Bug (needsinfo)
Extra method containing %...
Reported by: | Stephane | Owned by: | nobody |
---|---|---|---|
Component: | Uncategorized | Version: | 1.3 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
I would like to use the MySQL function DATE_FORMAT in Django 1.3.1.
This syntax is the most logical, but does not work:
Upload.objects.extra(select={'year': "DATE_FORMAT(`date_uploaded`, '%Y')"})
But this works:
Upload.objects.extra(select={'year': "%s"}, select_params=["DATE_FORMAT(`date_uploaded`, '%Y')"])
Is this a normal situation?
Best regards,
Stéphane
Change History (2)
comment:1 by , 13 years ago
comment:2 by , 13 years ago
Resolution: | → needsinfo |
---|---|
Status: | new → closed |
Could you describe more specifically what "doesn't work"? If you get an exception, could you paste the traceback?
PS: random suggestion:
Upload.objects.extra(select={'year': "DATE_FORMAT(`date_uploaded`, '%%Y')"})`
(with two % — % is the escape character for parameter substitution in Django's ORM, it must be escaped too)
Sorry, the above code does not work too:
{{{Upload.objects.extra(select={'year': "%s"}, select_params=DATE_FORMAT(`date_uploaded`, '%Y'))}}