开发者

escaping for objects.raw()

开发者 https://www.devze.com 2023-03-15 10:16 出处:网络
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 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

0

精彩评论

暂无评论...
验证码 换一张
取 消