... forms import ArticleForm >>> ArticleFormSet = formset_factory ( ArticleForm , absolute_max = 1500 ) >>> data = { ... "form-TOTAL_FORMS" : "1501" , ... "form-INITIAL_FORMS" : "0" , ... } >>> formset = ArticleFormSet ( data ) >>> len ( formset . forms ) ... actory >>> from myapp.forms import ArticleForm >>> ArticleFormSet = formset_factory ( ArticleForm ) >>> data = { ... "form-TOTAL_FORMS" : "1" , ... "form-INITIAL_FORMS" : "0" , ... } >>> formset = ArticleFormSet ( data ) >>> formset . is_valid () True ... フォームセットは十分に賢いので、変更されていない余分なフォームは無視します。無効な記事を提供すると、: >>> data = { ... "form-TOTAL_FORMS" : "2" , ... "form-INITIAL_FORMS" : "0" , ... "form-0-title" : "Test" , ... "form-0-pub_date" : "1904-06-16" , ... " ... ... forms import ArticleForm >>> ArticleFormSet = formset_factory ( ArticleForm , absolute_max = 1500 ) >>> data = { ... "form-TOTAL_FORMS" : "1501" , ... "form-INITIAL_FORMS" : "0" , ... } >>> formset = ArticleFormSet ( data ) >>> len ( formset . forms ) ... actory >>> from myapp.forms import ArticleForm >>> ArticleFormSet = formset_factory ( ArticleForm ) >>> data = { ... "form-TOTAL_FORMS" : "1" , ... "form-INITIAL_FORMS" : "0" , ... } >>> formset = ArticleFormSet ( data ) >>> formset . is_valid () True ... フォームセットは十分に賢いので、変更されていない余分なフォームは無視します。無効な記事を提供すると、: >>> data = { ... "form-TOTAL_FORMS" : "2" , ... "form-INITIAL_FORMS" : "0" , ... "form-0-title" : "Test" , ... "form-0-pub_date" : "1904-06-16" , ... " ... ... mple would use: 1 query to fetch books N queries, where N is the number of books, to fetch the missing author field …for a total of 1+N queries. This query pattern is known as the "N+1 queries problem" because it often leads to performance issues when ... e above example would use: 1 query to fetch books 1 query to fetch all missing author fields for the batch of books …for a total of 2 queries. The batch query makes this mode a lot more efficient than FETCH_ONE and is similar to an on-demand call to Q ... ... mple would use: 1 query to fetch books N queries, where N is the number of books, to fetch the missing author field …for a total of 1+N queries. This query pattern is known as the "N+1 queries problem" because it often leads to performance issues when ... e above example would use: 1 query to fetch books 1 query to fetch all missing author fields for the batch of books …for a total of 2 queries. The batch query makes this mode a lot more efficient than FETCH_ONE and is similar to an on-demand call to Q ... ... ンの前のエラー行の内容。 'during' : エラーを発生させたトークン。 'after' : エラーを発生させたトークンの後のエラー行の内容。 'total' : source_lines の行数。 'top' : source_lines が始まる行番号。 'bottom' : source_lines が終了する行番号。 上記のテンプレー ... " ), ( 8 , "" ), ], "line" : 4 , "before" : "Hello " , "during" : "{ % s yntax error %}" , "after" : " {{ world }} \n " , "total" : 9 , "bottom" : 9 , "top" : 1 , } Origin API と サードパーティとの統合 ¶ Djangoテンプレートでは、 template.origin 属性を ... ... ンの前のエラー行の内容。 'during' : エラーを発生させたトークン。 'after' : エラーを発生させたトークンの後のエラー行の内容。 'total' : source_lines の行数。 'top' : source_lines が始まる行番号。 'bottom' : source_lines が終了する行番号。 上記のテンプレー ... " ), ( 8 , "" ), ], "line" : 4 , "before" : "Hello " , "during" : "{ % s yntax error %}" , "after" : " {{ world }} \n " , "total" : 9 , "bottom" : 9 , "top" : 1 , } Origin API と サードパーティとの統合 ¶ Djangoテンプレートでは、 template.origin 属性を ... ... ManyToManyField ( Book ) チートシート ¶ お急ぎですか? 上のモデルを使った場合の一般的な集計クエリは以下のようになります: # Total number of books. >>> Book . objects . count () 2452 # Total number of books with publisher=BaloneyPress >>> Book . objects ... -> Book の逆多対多のホップを指定するために 'book' を使用していることに注意してください): >>> Author . objects . annotate ( total_pages = Sum ( "book__pages" )) ( QuerySet に含まれる Author は total_pages 属性を持ちます。別名が指定されなければ、 book__ ... ... ManyToManyField ( Book ) チートシート ¶ お急ぎですか? 上のモデルを使った場合の一般的な集計クエリは以下のようになります: # Total number of books. >>> Book . objects . count () 2452 # Total number of books with publisher=BaloneyPress >>> Book . objects ... -> Book の逆多対多のホップを指定するために 'book' を使用していることに注意してください): >>> Author . objects . annotate ( total_pages = Sum ( "book__pages" )) ( QuerySet に含まれる Author は total_pages 属性を持ちます。別名が指定されなければ、 book__ ... ... Subquery , Sum >>> comments = Comment . objects . filter ( post = OuterRef ( "pk" )) . order_by () . values ( "post" ) >>> total_comments = comments . annotate ( total = Sum ( "length" )) . values ( "total" ) >>> Post . objects . filter ( length__gt = ... Subquery ( total_comments )) 最初の filter(...) はサブクエリを関連するパラメータに制限します。 order_by() は Comment モデルのデフォルトの o ... 。これらのクエリセットメソッドを適用する順番は重要です。この場合、サブクエリは1つのカラムに限定する必要があるため、 values('total') が必要となります。 これは Subquery 内で集計を行う唯一の方法です。 aggregate() を使用すると、クエリセットを評価しようとし ... ... Subquery , Sum >>> comments = Comment . objects . filter ( post = OuterRef ( "pk" )) . order_by () . values ( "post" ) >>> total_comments = comments . annotate ( total = Sum ( "length" )) . values ( "total" ) >>> Post . objects . filter ( length__gt = ... Subquery ( total_comments )) 最初の filter(...) はサブクエリを関連するパラメータに制限します。 order_by() は Comment モデルのデフォルトの o ... 。これらのクエリセットメソッドを適用する順番は重要です。この場合、サブクエリは1つのカラムに限定する必要があるため、 values('total') が必要となります。 これは Subquery 内で集計を行う唯一の方法です。 aggregate() を使用すると、クエリセットを評価しようとし ... 2026年10月08日