... ue は null=False のフィールドでも使用できますが、この場合、 clean() を実装し、欠損値をプログラムで補完する必要があります。 choices ¶ Field. choices [ソース] ¶ このフィールドの選択肢として使用するための、以下で説明する形式のマッピングまたはイテラブルです ... 。choices が指定された場合、 モデルのバリデーション によって強制的に、デフォルトのフォームウィジェットが通常のテキストフィールドの代 ... マッピングが指定された場合、キー要素はモデルに設定される実際の値で、2番目の要素は人間が読める名前です。例えば YEAR_IN_SCHOOL_CHOICES = { "FR" : "Freshman" , "SO" : "Sophomore" , "JR" : "Junior" , "SR" : "Senior" , "GR" : "Graduate" , } また、 sequence とし ... ... ue は null=False のフィールドでも使用できますが、この場合、 clean() を実装し、欠損値をプログラムで補完する必要があります。 choices ¶ Field. choices [ソース] ¶ このフィールドの選択肢として使用するための、以下で説明する形式のマッピングまたはイテラブルです ... 。choices が指定された場合、 モデルのバリデーション によって強制的に、デフォルトのフォームウィジェットが通常のテキストフィールドの代 ... マッピングが指定された場合、キー要素はモデルに設定される実際の値で、2番目の要素は人間が読める名前です。例えば YEAR_IN_SCHOOL_CHOICES = { "FR" : "Freshman" , "SO" : "Sophomore" , "JR" : "Junior" , "SR" : "Senior" , "GR" : "Graduate" , } また、 sequence とし ... ... output_field = models . BigIntegerField (), db_persist = True , ) フィールドの選択肢を宣言する際のオプションが増加 ¶ Field.choices (モデルフィールド用) と ChoiceField.choices (フォームフィールド用) により、値を宣言する際の柔軟性が向上しました。以前のバー ... ジョンの Django では、 choices は 2 タプルのリストか、 列挙型 のサブクラスである必要がありましたが、後者の場合、 .choices 属性にアクセスして、期待される形 ... 式で値を提供する必要がありました: from django.db import models Medal = models . TextChoices ( "Medal" , "GOLD SILVER BRONZE" ) SPORT_CHOICES = [ ( "Martial Arts" , [( "judo" , "Judo" ), ( "karate" , "Karate" )]), ( ... ... output_field = models . BigIntegerField (), db_persist = True , ) フィールドの選択肢を宣言する際のオプションが増加 ¶ Field.choices (モデルフィールド用) と ChoiceField.choices (フォームフィールド用) により、値を宣言する際の柔軟性が向上しました。以前のバー ... ジョンの Django では、 choices は 2 タプルのリストか、 列挙型 のサブクラスである必要がありましたが、後者の場合、 .choices 属性にアクセスして、期待される形 ... 式で値を提供する必要がありました: from django.db import models Medal = models . TextChoices ( "Medal" , "GOLD SILVER BRONZE" ) SPORT_CHOICES = [ ( "Martial Arts" , [( "judo" , "Judo" ), ( "karate" , "Karate" )]), ( ... ... エラーメッセージには %(value)s が含まれていることがあり、選択された選択肢に置き換えられます。 1つの追加引数を受け取ります: choices [ソース] ¶ このフィールドの選択肢として使用する2値タプルの iterable 、 列挙型 、またはそのようなイテラブルを返す呼び出し可 ... 能オブジェクトのいずれか。この引数は、モデルフィールドの choices 引数と同じ形式を受け入れます。詳細については、 モデルフィールドのリファレンスドキュメント を参照してください。引数が呼び出 ... ecified location should be included. Either this or allow_files must be True . FilePathField has the following method: set_choices () [ソース] ¶ New in Django 6.1. Scans the directory at path and refreshes the field's choices. This is called automatical ... ... エラーメッセージには %(value)s が含まれていることがあり、選択された選択肢に置き換えられます。 1つの追加引数を受け取ります: choices [ソース] ¶ このフィールドの選択肢として使用する2値タプルの iterable 、 列挙型 、またはそのようなイテラブルを返す呼び出し可 ... 能オブジェクトのいずれか。この引数は、モデルフィールドの choices 引数と同じ形式を受け入れます。詳細については、 モデルフィールドのリファレンスドキュメント を参照してください。引数が呼び出 ... ecified location should be included. Either this or allow_files must be True . FilePathField has the following method: set_choices () [ソース] ¶ New in Django 6.1. Scans the directory at path and refreshes the field's choices. This is called automatical ... ... 際にセットできます。以下の例では、 SelectDateWidget に対して years 属性がセットされます: from django import forms BIRTH_YEAR_CHOICES = [ "1980" , "1981" , "1982" ] FAVORITE_COLORS_CHOICES = { "blue" : "Blue" , "green" : "Green" , "black" : "Black" , } cla ... ss SimpleForm ( forms . Form ): birth_year = forms . DateField ( widget = forms . SelectDateWidget ( years = BIRTH_YEAR_CHOICES ) ) favorite_colors = forms . MultipleChoiceField ( required = False , widget = forms . CheckboxSelectMultiple , choices = ... FAVORITE_COLORS_CHOICES , ) 使用可能なウィジェットとそれぞれの引数の詳細については、 ビルトインのウィジェット を参照してください。 ウィジェットのイ ... ... 際にセットできます。以下の例では、 SelectDateWidget に対して years 属性がセットされます: from django import forms BIRTH_YEAR_CHOICES = [ "1980" , "1981" , "1982" ] FAVORITE_COLORS_CHOICES = { "blue" : "Blue" , "green" : "Green" , "black" : "Black" , } cla ... ss SimpleForm ( forms . Form ): birth_year = forms . DateField ( widget = forms . SelectDateWidget ( years = BIRTH_YEAR_CHOICES ) ) favorite_colors = forms . MultipleChoiceField ( required = False , widget = forms . CheckboxSelectMultiple , choices = ... FAVORITE_COLORS_CHOICES , ) 使用可能なウィジェットとそれぞれの引数の詳細については、 ビルトインのウィジェット を参照してください。 ウィジェットのイ ... ... ng to the admin index page. The admin's FilteredSelectMultiple widget now uses <optgroup> s to preserve named groups (e.g. choices=[("Group", [("1", "Item")]), ...] ). When ModelAdmin.list_select_related is False (the default), the change list now selec ... CE_LABEL defines a more accessible and translatable default label for the blank choice in forms, which is appended to most choices lists. The transitional setting USE_BLANK_CHOICE_DASH allows you to revert back to the old default label. FilePathField no ... w provides a set_choices() method to scan the directory at path and refresh the field's choices. This allows per-request refreshing when called in ... ... ng to the admin index page. The admin's FilteredSelectMultiple widget now uses <optgroup> s to preserve named groups (e.g. choices=[("Group", [("1", "Item")]), ...] ). When ModelAdmin.list_select_related is False (the default), the change list now selec ... CE_LABEL defines a more accessible and translatable default label for the blank choice in forms, which is appended to most choices lists. The transitional setting USE_BLANK_CHOICE_DASH allows you to revert back to the old default label. FilePathField no ... w provides a set_choices() method to scan the directory at path and refresh the field's choices. This allows per-request refreshing when called in ... 2026年10月08日