Opened 11 years ago

Closed 11 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


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,


Change History (2)

comment:1 Changed 11 years ago by anonymous

Sorry, the above code does not work too:

{{{Upload.objects.extra(select={'year': "%s"}, select_params=DATE_FORMAT(`date_uploaded`, '%Y')?)}}

comment:2 Changed 11 years ago by Aymeric Augustin

Resolution: needsinfo
Status: newclosed

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)

Note: See TracTickets for help on using tickets.
Back to Top