0

条件を取得するためのループを作成しました。

for level in levels:
    requete += ' and level_concat like %'+level+'%'

そして私は私のクエリで作った:

countries = Country.objects.extra(where=['continent_id = "'+continent_id+'"', requete])

where句に条件を追加しようとしましたが、エラーが返されました:

not enough arguments for format string

尊敬される結果:

SELECT * FROM `Country` WHERE country_id = "US-51" AND level_concat LIKE %level_test%

requete「where」句に追加する方法はありますか?

4

2 に答える 2

0

%クエリで記号をエスケープする必要があると思います:

' and level_concat like %%'+level+'%%'
于 2013-10-14T16:21:21.510 に答える