escaping for objects.raw()
I need a custom SQL query and try to u开发者_JS百科se this:
Log.objects.raw("SELECT pub_date FROM foo_log GROUP BY DATE_FORMAT(pub_date,'%Y%m%d')")
I get this error: TypeError: not enough arguments for format string
So how can I escape this %Y strings?
Generally, you escape a %
with another %
, e.g.:
Log.objects.raw("SELECT pub_date FROM foo_log GROUP BY DATE_FORMAT(pub_date,'%%Y%%m%%d')")
Rather then raw SQL you could use dates for the above query.
Log.objects.dates('pub_date', 'day')
would return all the distinct dates by y/m/d
精彩评论