... e import date , timedelta >>> from django.db.models import Case , Value , When >>> Client . objects . create ( ... name = "Jane Doe" , ... account_type = Client . REGULAR , ... registered_on = date . today () - timedelta ( days = 36 ), ... ) >>> Clie ... M , then = Value ( "10%" )), ... default = Value ( "0%" ), ... ), ... ) . values_list ( "name" , "discount" ) <QuerySet [('Jane Doe', '0%'), ('James Smith', '5%'), ('Jack Black', '10%')]> Case() は任意の数の When() オブジェクトを引数として受け取ること ... ago , then = Value ( "5%" )), ... default = Value ( "0%" ), ... ) ... ) . values_list ( "name" , "discount" ) <QuerySet [('Jane Doe', '5%'), ('James Smith', '0%'), ('Jack Black', '10%')]> 注釈 条件は順番に評価されるので、上の例では2番目の条件がJane D ... ... e import date , timedelta >>> from django.db.models import Case , Value , When >>> Client . objects . create ( ... name = "Jane Doe" , ... account_type = Client . REGULAR , ... registered_on = date . today () - timedelta ( days = 36 ), ... ) >>> Clie ... M , then = Value ( "10%" )), ... default = Value ( "0%" ), ... ), ... ) . values_list ( "name" , "discount" ) <QuerySet [('Jane Doe', '0%'), ('James Smith', '5%'), ('Jack Black', '10%')]> Case() は任意の数の When() オブジェクトを引数として受け取ること ... ago , then = Value ( "5%" )), ... default = Value ( "0%" ), ... ) ... ) . values_list ( "name" , "discount" ) <QuerySet [('Jane Doe', '5%'), ('James Smith', '0%'), ('Jack Black', '10%')]> 注釈 条件は順番に評価されるので、上の例では2番目の条件がJane D ... ... () slightly more efficient. send_mail() with multiple to addresses sends a single email message, with john@example.com and jane@example.com both appearing in the "To:" field: send_mail ( "Subject" , "Message." , "from@example.com" , [ "john@example.c ... om" , "jane@example.com" ], ) send_mass_mail() sends a separate message per datatuple element, so john@example.com and jane@example.co ... "Subject" , "Message." , "from@example.com" , [ "john@example.com" ]), ( "Subject" , "Message." , "from@example.com" , [ "jane@example.com" ]), ) send_mass_mail ( datatuple ) mail_admins() ¶ mail_admins ( subject , message , * , fail_silently = Fals ... ... () slightly more efficient. send_mail() with multiple to addresses sends a single email message, with john@example.com and jane@example.com both appearing in the "To:" field: send_mail ( "Subject" , "Message." , "from@example.com" , [ "john@example.c ... om" , "jane@example.com" ], ) send_mass_mail() sends a separate message per datatuple element, so john@example.com and jane@example.co ... "Subject" , "Message." , "from@example.com" , [ "john@example.com" ]), ( "Subject" , "Message." , "from@example.com" , [ "jane@example.com" ]), ) send_mass_mail ( datatuple ) mail_admins() ¶ mail_admins ( subject , message , * , fail_silently = Fals ... ... の SQL を実行できます: >>> for p in Person . objects . raw ( "SELECT * FROM myapp_person" ): ... print ( p ) ... John Smith Jane Jones この例はたいしてエキサイティングではありません。これは Person.objects.all() を実行したのと全く同じです。しかしながら ... # This will be retrieved by the original query ... p . last_name , # This will be retrieved on demand ... ) ... John Smith Jane Jones 見た目上は、そのクエリが名前と苗字を両方取得しているように見えます。しかし、この例は実際には 3 つのクエリを発行してい ... ... の SQL を実行できます: >>> for p in Person . objects . raw ( "SELECT * FROM myapp_person" ): ... print ( p ) ... John Smith Jane Jones この例はたいしてエキサイティングではありません。これは Person.objects.all() を実行したのと全く同じです。しかしながら ... # This will be retrieved by the original query ... p . last_name , # This will be retrieved on demand ... ) ... John Smith Jane Jones 見た目上は、そのクエリが名前と苗字を両方取得しているように見えます。しかし、この例は実際には 3 つのクエリを発行してい ... ... キーワード引数を使って、テンプレートに追加のコンテキストを渡すことができます: {% include "name_snippet.html" with person = "Jane" greeting = "Hello" %} あらかじめ準備された変数だけを使って (あるいは変数をまったく使わずに) 出力させたい場合は only オプシ ... ... キーワード引数を使って、テンプレートに追加のコンテキストを渡すことができます: {% include "name_snippet.html" with person = "Jane" greeting = "Hello" %} あらかじめ準備された変数だけを使って (あるいは変数をまったく使わずに) 出力させたい場合は only オプシ ... 2026年10月08日