... text }} </ h1 ></ legend > {% if error_message %} < p >< strong > {{ error_message }} </ strong ></ p > {% endif %} {% for choice in question.choice_set.all %} < input type = "radio" name = "choice" id = "choice {{ forloop .counter }} " value = " {{ ch ... oice.id }} " > < label for = "choice {{ forloop .counter }} " > {{ choice.choice_text }} </ label >< br > {% endfor %} </ fieldset > < input type = "submit" va ... の選択肢のラジオボタンを表示するものです。各ラジオボタンの value は、関連する質問の選択肢のIDです。各ラジオボタンの name は "choice" です。つまり、投票者がラジオボタンの1つを選択し、フォームを送信すると、POSTデータ choice=# (#は選んだ選択肢のID)が送信さ ... ... o update your database schema to match your current models. これから開発する簡単な poll アプリケーションでは、 Question と Choice の2つのモデルを作成します。 Question には質問文と公開日時があります。 Choice には選択肢のテキストと vote という2つのフィー ... ルドがあります。各 Choice は1つの Question に関連づけられています。 Django では、こうした概念を簡単な Python クラスで表現できます。 polls/models.py ... el ): question_text = models . CharField ( max_length = 200 ) pub_date = models . DateTimeField ( "date published" ) class Choice ( models . Model ): question = models . ForeignKey ( Question , on_delete = models . CASCADE ) choice_text = models . Char ... ... 以下のように表示されます。 リレーション先オブジェクトの追加 OK、 Question の管理ページはできました。しかし Question は複数の Choice を持つのに、管理ページには表示されていませんね。 現状はそうですが、表示はできます。 この問題を解決するには2つの方法がありま ... す。1つ目は、 Question と同じようにadminに Choice を登録する方法です: polls/admin.py from django.contrib import admin from .models import Choice , Question # ... admin . si ... te . register ( Choice ) これで、 Django の管理サイト上で「Choice」 を選べます。「Choice の追加」フォーム は以下のようになります。 このフォームで ... ... ト)の場合、値から先頭と末尾の空白が削除されます。 empty_value 「空」を表すのに使用する値です。デフォルトは空の文字列です。 ChoiceField class ChoiceField ( ** kwargs ) [ソース] デフォルトのウィジェット: Select 空の値: '' (空の文字列) 正規化後の値: 文字列 ... になります。 指定された値が選択肢のリスト内に存在することを検証します。 エラーメッセージのキー: required , invalid_choice invalid_choice エラーメッセージには %(value)s が含まれていることがあり、選択された選択肢に置き換えられます。 1つの追加引数 ... を受け取ります: choices [ソース] このフィールドの選択肢として使用する2値タプルの iterable 、 列挙型 、またはそのようなイテラブルを返す呼び出し可能 ... ... ンプレートは次のようになります: polls/templates/polls/detail.html < h1 > {{ question.question_text }} </ h1 > < ul > {% for choice in question.choice_set.all %} < li > {{ choice.choice_text }} </ li > {% endfor %} </ ul > テンプレートシステムは、変数の属 ... 索に失敗すると、リストインデックスでの検索を行います。 メソッドの呼び出しは {% for %} ループの中で行われています。 question.choice_set.all は、 Python コードの question.choice_set.all() と解釈されます。その結果、 Choice オブジェクトからなるイテレーション ... ... 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 sele ... s to stylesheet links in form media. See paths as objects for more details. The new constant django.db.models.fields.BLANK_CHOICE_LABEL defines a more accessible and translatable default label for the blank choice in forms, which is appended to most ch ... oices lists. The transitional setting USE_BLANK_CHOICE_DASH allows you to revert back to the old default label. FilePathField now provides a set_choices() method to scan the dir ... ... tersection() crashed due to mismatching columns ( #29229 ). Fixed a regression in Django 1.11 where an empty choice could be initially selected for the SelectMultiple and CheckboxSelectMultiple widgets ( #29273 ). ... ... L injection if untrusted data was used as a kind / lookup_name value. Applications that constrain the lookup name and kind choice to a known safe list are unaffected. ... ... L injection if untrusted data was used as a kind / lookup_name value. Applications that constrain the lookup name and kind choice to a known safe list are unaffected. ... ... t were previously loaded. For example, with the tutorial's models: >>> first_poll = Poll . objects . all ()[ 0 ] >>> first_choice = first_poll . choice_set . all ()[ 0 ] >>> first_choice . poll is first_poll True In Django 1.5, the third line no longer ... triggers a new SQL query to fetch first_choice.poll ; it was set by the second line. For one-to-one relationships, both sides can be cached. For many-to-one relationship ... f 1000 forms. This limit can be raised by explicitly setting a higher value for max_num . その他 django.forms.ModelMultipleChoiceField now returns an empty QuerySet as the empty value instead of an empty list. int_to_base36() properly raises a TypeErro ... 2026年10月08日