... [<Article: John's second story>, <Article: This is a test>]> >>> Article . objects . filter ( reporter__in = [ 1 , 2 ]) . distinct () <QuerySet [<Article: John's second story>, <Article: Paul's story>, <Article: This is a test>]> >>> Article . objects . ... filter ( reporter__in = [ r , r2 ]) . distinct () <QuerySet [<Article: John's second story>, <Article: Paul's story>, <Article: This is a test>]> インスタンスのリテラルの ... もできます: >>> Article . objects . filter ( ... reporter__in = Reporter . objects . filter ( first_name = "John" ) ... ) . distinct () <QuerySet [<Article: John's second story>, <Article: This is a test>]> 逆方向のクエリ: >>> Reporter . objects . filter ... ... [<Article: John's second story>, <Article: This is a test>]> >>> Article . objects . filter ( reporter__in = [ 1 , 2 ]) . distinct () <QuerySet [<Article: John's second story>, <Article: Paul's story>, <Article: This is a test>]> >>> Article . objects . ... filter ( reporter__in = [ r , r2 ]) . distinct () <QuerySet [<Article: John's second story>, <Article: Paul's story>, <Article: This is a test>]> インスタンスのリテラルの ... もできます: >>> Article . objects . filter ( ... reporter__in = Reporter . objects . filter ( first_name = "John" ) ... ) . distinct () <QuerySet [<Article: John's second story>, <Article: This is a test>]> 逆方向のクエリ: >>> Reporter . objects . filter ... ... es Python>, <Article: NASA uses Python>]> >>> Article . objects . filter ( publications__title__startswith = "Science" ) . distinct () <QuerySet [<Article: NASA uses Python>]> count() 関数は distinct() も尊重します: >>> Article . objects . filter ( publi ... le__startswith = "Science" ) . count () 2 >>> Article . objects . filter ( publications__title__startswith = "Science" ) . distinct () . count () 1 >>> Article . objects . filter ( publications__in = [ 1 , 2 ]) . distinct () <QuerySet [<Article: Django l ... u build web apps easily>, <Article: NASA uses Python>]> >>> Article . objects . filter ( publications__in = [ p1 , p2 ]) . distinct () <QuerySet [<Article: Django lets you build web apps easily>, <Article: NASA uses Python>]> 逆の多対多クエリもサポートさ ... ... る引数 ( nulls_first と nulls_last )をとります。 Be cautious when ordering by fields in related models if you are also using distinct() . See the note in distinct() for an explanation of how related model ordering can change the expected results. 注釈 複数 ... () on it has no real effect (the ordering was undefined prior to calling reverse() , and will remain undefined afterward). distinct() ¶ distinct ( * fields ) ¶ SQL クエリで SELECT DISTINCT を使用した新しい QuerySet を返します。これにより、クエリ結果から重 ... クエリが複数のテーブルにまたがっている場合、 QuerySet が評価されたときに重複した結果を得る可能性があります。このような場合は distinct() を使用します。 注釈 order_by() の呼び出しで使用されるフィールドはすべて、SQL の SELECT 列に含まれます。これは distinct() ... ... る引数 ( nulls_first と nulls_last )をとります。 Be cautious when ordering by fields in related models if you are also using distinct() . See the note in distinct() for an explanation of how related model ordering can change the expected results. 注釈 複数 ... () on it has no real effect (the ordering was undefined prior to calling reverse() , and will remain undefined afterward). distinct() ¶ distinct ( * fields ) ¶ SQL クエリで SELECT DISTINCT を使用した新しい QuerySet を返します。これにより、クエリ結果から重 ... クエリが複数のテーブルにまたがっている場合、 QuerySet が評価されたときに重複した結果を得る可能性があります。このような場合は distinct() を使用します。 注釈 order_by() の呼び出しで使用されるフィールドはすべて、SQL の SELECT 列に含まれます。これは distinct() ... ... es Python>, <Article: NASA uses Python>]> >>> Article . objects . filter ( publications__title__startswith = "Science" ) . distinct () <QuerySet [<Article: NASA uses Python>]> count() 関数は distinct() も尊重します: >>> Article . objects . filter ( publi ... le__startswith = "Science" ) . count () 2 >>> Article . objects . filter ( publications__title__startswith = "Science" ) . distinct () . count () 1 >>> Article . objects . filter ( publications__in = [ 1 , 2 ]) . distinct () <QuerySet [<Article: Django l ... u build web apps easily>, <Article: NASA uses Python>]> >>> Article . objects . filter ( publications__in = [ p1 , p2 ]) . distinct () <QuerySet [<Article: Django lets you build web apps easily>, <Article: NASA uses Python>]> 逆の多対多クエリもサポートさ ... ... ち、ほとんどの集計関数は default キーワード引数も持っています。 汎用的な集計関数 ¶ ArrayAgg ¶ class ArrayAgg ( expression , distinct = False , filter = None , default = None , order_by = () , ** extra ) ¶ null を含む値のリストを配列に連結して返すか、値がな ... い場合は default を返す。 distinct ¶ オプションの真偽値引数で、配列の値を区別するかどうかを指定する。デフォルトは False です。 order_by ¶ 結果リスト内の要素の ... . objects . aggregate ( boolor = BoolOr ( Q ( rank__gt = 2 ))) {'boolor': False} JSONBAgg ¶ class JSONBAgg ( expressions , distinct = False , filter = None , default = None , order_by = () , ** extra ) ¶ 入力値を JSON 配列として返します。値がない場合は d ... ... aint ( * expressions , fields = () , name , condition = None , deferrable = None , include = None , opclasses = () , nulls_distinct = None , violation_error_code = None , violation_error_message = None ) [ソース] ¶ Creates a uniqueness guarantee in the d ... ar_pattern_ops を使用する一意なインデックスを作成します。 opclasses はPostgreSQL以外のデータベースでは無視されます。 nulls_distinct ¶ UniqueConstraint. nulls_distinct ¶ ユニーク制約の対象となる NULL 値を含む行を、互いに異なる行とみなすかどうかを指定します ... e となるデータベースのデフォルト値を使用します。 例: UniqueConstraint ( name = "ordering" , fields = [ "ordering" ], nulls_distinct = False ) これは、 ordering カラムに NULL 値を格納できるのは1行だけというユニーク制約を作成します。 Unique constraints wit ... ... ち、ほとんどの集計関数は default キーワード引数も持っています。 汎用的な集計関数 ¶ ArrayAgg ¶ class ArrayAgg ( expression , distinct = False , filter = None , default = None , order_by = () , ** extra ) ¶ null を含む値のリストを配列に連結して返すか、値がな ... い場合は default を返す。 distinct ¶ オプションの真偽値引数で、配列の値を区別するかどうかを指定する。デフォルトは False です。 order_by ¶ 結果リスト内の要素の ... . objects . aggregate ( boolor = BoolOr ( Q ( rank__gt = 2 ))) {'boolor': False} JSONBAgg ¶ class JSONBAgg ( expressions , distinct = False , filter = None , default = None , order_by = () , ** extra ) ¶ 入力値を JSON 配列として返します。値がない場合は d ... ... aint ( * expressions , fields = () , name , condition = None , deferrable = None , include = None , opclasses = () , nulls_distinct = None , violation_error_code = None , violation_error_message = None ) [ソース] ¶ Creates a uniqueness guarantee in the d ... ar_pattern_ops を使用する一意なインデックスを作成します。 opclasses はPostgreSQL以外のデータベースでは無視されます。 nulls_distinct ¶ UniqueConstraint. nulls_distinct ¶ ユニーク制約の対象となる NULL 値を含む行を、互いに異なる行とみなすかどうかを指定します ... e となるデータベースのデフォルト値を使用します。 例: UniqueConstraint ( name = "ordering" , fields = [ "ordering" ], nulls_distinct = False ) これは、 ordering カラムに NULL 値を格納できるのは1行だけというユニーク制約を作成します。 Unique constraints wit ... 2026年10月08日