开发者

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

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜