Opened 3 years ago

Closed 3 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 Changed 3 years ago by anonymous

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

Sorry, the above code does not work too:

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

comment:2 Changed 3 years ago by aaugustin

  • Resolution set to needsinfo
  • Status changed from new to 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)

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