... hen ( Q ( then = 0 ), then = 1 ) Case ¶ class Case ( * cases , ** extra ) [ソース] ¶ Case() 式は Python の if ... elif ... else 文のようなものです。指定された When() オブジェクトの各 condition は 1 つが True と評価されるまで順番に評価されます。一致し ... 件がJane DoeとJack Blackの両方にマッチしても正しい結果が得られることを覚えておいてください。これは Python の if ... elif ... else 文と同じように動作します。 case() は filter() 句でも使えます。たとえば、1ヶ月以上前に登録されたゴールドクライアントと1年以 ... データベースでは、これは CASE ステートメントを使ってエミュレートされます: SELECT count ( CASE WHEN account_type = 1 THEN id ELSE null ) as regular , count ( CASE WHEN account_type = 2 THEN id ELSE null ) as gold , count ( CASE WHEN account_type = 3 TH ... ... hen ( Q ( then = 0 ), then = 1 ) Case ¶ class Case ( * cases , ** extra ) [ソース] ¶ Case() 式は Python の if ... elif ... else 文のようなものです。指定された When() オブジェクトの各 condition は 1 つが True と評価されるまで順番に評価されます。一致し ... 件がJane DoeとJack Blackの両方にマッチしても正しい結果が得られることを覚えておいてください。これは Python の if ... elif ... else 文と同じように動作します。 case() は filter() 句でも使えます。たとえば、1ヶ月以上前に登録されたゴールドクライアントと1年以 ... データベースでは、これは CASE ステートメントを使ってエミュレートされます: SELECT count ( CASE WHEN account_type = 1 THEN id ELSE null ) as regular , count ( CASE WHEN account_type = 2 THEN id ELSE null ) as gold , count ( CASE WHEN account_type = 3 TH ... ... ます。たとえば: from django.conf import settings def my_view ( request ): if settings . SITE_ID == 3 : # Do something. pass else : # Do something else. pass It's fragile to hardcode the site IDs like that, in case they change. The cleaner way of accom ... _view ( request ): current_site = get_current_site ( request ) if current_site . domain == "foo.com" : # Do something pass else : # Do something else. pass これには、サイトフレームワークがインストールされているかどうかを確認するという利点もあります。 ... out_request (): current_site = Site . objects . get_current () if current_site . domain == "foo.com" : # Do something pass else : # Do something else. pass 表示用の現在のドメインを取得する ¶ LJWorld.com と Lawrence.com はどちらも、ニュースが発生したと ... ... ush the branch to your fork and open a pull request. See Submitting contributions for the full process. Continuing someone else's work ¶ If you're continuing the work from someone else's pull request on GitHub, things can be tricky. You need to pull ... ssing tickets Methods to find tickets Claiming a ticket Creating a branch for the ticket Starting fresh Continuing someone else's work 前のトピックへ 新しいコントリビューターへのアドバイス 次のトピックへ Contributing code 関連キーワード ticket tests ... ... ush the branch to your fork and open a pull request. See Submitting contributions for the full process. Continuing someone else's work ¶ If you're continuing the work from someone else's pull request on GitHub, things can be tricky. You need to pull ... ssing tickets Methods to find tickets Claiming a ticket Creating a branch for the ticket Starting fresh Continuing someone else's work 前のトピックへ 新しいコントリビューターへのアドバイス 次のトピックへ Contributing code 関連キーワード ticket xf git ... ... ます。たとえば: from django.conf import settings def my_view ( request ): if settings . SITE_ID == 3 : # Do something. pass else : # Do something else. pass It's fragile to hardcode the site IDs like that, in case they change. The cleaner way of accom ... _view ( request ): current_site = get_current_site ( request ) if current_site . domain == "foo.com" : # Do something pass else : # Do something else. pass これには、サイトフレームワークがインストールされているかどうかを確認するという利点もあります。 ... out_request (): current_site = Site . objects . get_current () if current_site . domain == "foo.com" : # Do something pass else : # Do something else. pass 表示用の現在のドメインを取得する ¶ LJWorld.com と Lawrence.com はどちらも、ニュースが発生したと ... ... if form . is_valid (): handle_uploaded_file ( request . FILES [ "file" ]) return HttpResponseRedirect ( "/success/url/" ) else : form = UploadFileForm () return render ( request , "upload.html" , { "form" : form }) ここで、 request.FILES をフォームの ... , request . FILES ) if form . is_valid (): # file is saved form . save () return HttpResponseRedirect ( "/success/url/" ) else : form = ModelFormWithFileField () return render ( request , "upload.html" , { "form" : form }) 手動でオブジェクトを作成す ... ithFileField ( file_field = request . FILES [ "file" ]) instance . save () return HttpResponseRedirect ( "/success/url/" ) else : form = UploadFileForm () return render ( request , "upload.html" , { "form" : form }) リクエストの外で手動でオブジェクト ... ... if form . is_valid (): handle_uploaded_file ( request . FILES [ "file" ]) return HttpResponseRedirect ( "/success/url/" ) else : form = UploadFileForm () return render ( request , "upload.html" , { "form" : form }) ここで、 request.FILES をフォームの ... , request . FILES ) if form . is_valid (): # file is saved form . save () return HttpResponseRedirect ( "/success/url/" ) else : form = ModelFormWithFileField () return render ( request , "upload.html" , { "form" : form }) 手動でオブジェクトを作成す ... ithFileField ( file_field = request . FILES [ "file" ]) instance . save () return HttpResponseRedirect ( "/success/url/" ) else : form = UploadFileForm () return render ( request , "upload.html" , { "form" : form }) リクエストの外で手動でオブジェクト ... ... thenticate ( username = "john" , password = "secret" ) if user is not None : # A backend authenticated the credentials ... else : # No backend authenticated the credentials ... request はオプションで、 HttpRequest のインスタンスを取ります。このインス ... icated を用いて次のように識別できます。 if request . user . is_authenticated : # Do something for authenticated users. ... else : # Do something for anonymous users. ... 非同期ビューでは次のようになります。 user = await request . auser () if user . i ... s_authenticated : # Do something for authenticated users. ... else : # Do something for anonymous users. ... ユーザーをログインさせる方法 ¶ 現在のセッションに接続したい認証ユーザーがいる場合 ... ... thenticate ( username = "john" , password = "secret" ) if user is not None : # A backend authenticated the credentials ... else : # No backend authenticated the credentials ... request はオプションで、 HttpRequest のインスタンスを取ります。このインス ... icated を用いて次のように識別できます。 if request . user . is_authenticated : # Do something for authenticated users. ... else : # Do something for anonymous users. ... 非同期ビューでは次のようになります。 user = await request . auser () if user . i ... s_authenticated : # Do something for authenticated users. ... else : # Do something for anonymous users. ... ユーザーをログインさせる方法 ¶ 現在のセッションに接続したい認証ユーザーがいる場合 ... 2026年10月08日