瀏覽代碼

Doc'd that RawSQL can be used with __in.

Simon Willison 4 年之前
父節點
當前提交
e53159747c
共有 1 個文件被更改,包括 5 次插入1 次删除
  1. 5 1
      docs/ref/models/expressions.txt

+ 5 - 1
docs/ref/models/expressions.txt

@@ -699,12 +699,16 @@ Sometimes database expressions can't easily express a complex ``WHERE`` clause.
 In these edge cases, use the ``RawSQL`` expression. For example::
 
     >>> from django.db.models.expressions import RawSQL
-    >>> queryset.annotate(val=RawSQL("select col from sometable where othercol = %s", (someparam,)))
+    >>> queryset.annotate(val=RawSQL("select col from sometable where othercol = %s", (param,)))
 
 These extra lookups may not be portable to different database engines (because
 you're explicitly writing SQL code) and violate the DRY principle, so you
 should avoid them if possible.
 
+``RawSQL`` expressions can also be used as the target of ``__in`` filters::
+
+    >>> queryset.filter(id__in=RawSQL("select id from sometable where col = %s", (param,)))
+
 .. warning::
 
     To protect against `SQL injection attacks