... を使用します: from django.db import models class Client ( models . Model ): REGULAR = "R" GOLD = "G" PLATINUM = "P" ACCOUNT_TYPE_CHOICES = { REGULAR : "Regular" , GOLD : "Gold" , PLATINUM : "Platinum" , } name = models . CharField ( max_length = 50 ) ... registered_on = models . DateField () account_type = models . CharField ( max_length = 1 , choices = ACCOUNT_TYPE_CHOICES , default = REGULAR , ) When class When ( condition ... import F , Q , When >>> # String arguments refer to fields; the following two examples are equivalent: >>> When ( account_type = Client . GOLD , then = "name" ) >>> When ( account_type = Client . GOLD , then = F ( "name" )) >>> # You can use field l ... ... は、 <!DOCTYPE html> を対象とした HTML5 シンタックスを使います。たとえば、XHTML スタイルである checked='checked' よりも、 checked といった ... グが適用され、CSS クラスや追加の属性はありません。 >>> f = CommentForm ( auto_id = False ) >>> print ( f ) <div>Name:<input type="text" name="name" required></div> <div>Url:<input type="url" name="url" required></div> <div>Comment:<input type="text" n ... 素を、名前用のウィジェットには特別な CSS クラスを指定したいかもしれません。また、HTML5 の異なる入力タイプを使用するために、 'type' 属性を指定することも可能です。これを行うには、ウィジェットを作成する際に Widget.attrs 引数を使用します。 class CommentFor ... ... inspectdb コマンドラインオプション loaddata コマンドラインオプション migrate コマンドラインオプション remove_stale_contenttypes コマンドラインオプション showmigrations コマンドラインオプション sqlflush コマンドラインオプション sqlmigrate コマンドライ ... コマンドラインオプション --include-partitions inspectdb コマンドラインオプション --include-stale-apps remove_stale_contenttypes コマンドラインオプション --include-views inspectdb コマンドラインオプション --indent dumpdata コマンドラインオプション -- ... メソッド) app_directories.Loader (django.template.loaders のクラス) app_index_template (AdminSite の属性) app_label (ContentType の属性) (Options の属性) app_name (ResolverMatch の属性) app_names (ResolverMatch の属性) AppCommand (django.core.manageme ... ... arField () ... >>> f = CommentForm ( initial = { "name" : "instance" }, auto_id = False ) >>> print ( f ) <div>Name:<input type="text" name="name" value="instance" required></div> <div>Url:<input type="url" name="url" required></div> <div>Comment:<in ... put type="text" name="comment" required></div> Form. get_initial_for_field ( field , field_name ) フォームフィールドの初期データを返 ... の表示方法を変更できます。 >>> f . as_div () . split ( "</div>" )[ 0 ] '<div><label for="id_subject">Subject:</label><input type="text" name="subject" maxlength="100" required id="id_subject">' >>> f [ "subject" ] . label = "Topic" >>> f . as_div () . ... ... ArticleFormSet () >>> for form in formset : ... print ( form ) ... <div><label for="id_form-0-title">Title:</label><input type="text" name="form-0-title" id="id_form-0-title"></div> <div><label for="id_form-0-pub_date">Pub date:</label><input type=" ... ... } ... ] ... ) >>> for form in formset : ... print ( form ) ... <div><label for="id_form-0-title">Title:</label><input type="text" name="form-0-title" value="Django is now open source" id="id_form-0-title"></div> <div><label for="id_form-0-pub_da ... te">Pub date:</label><input type="text" name="form-0-pub_date" value="2023-02-11" id="id_form-0-pub_date"></div> <div><label for="id_form-1-title">Title:</ ... ... types アプリケーションの中心にあるのは、 django.contrib.contenttypes.models.ContentType にある ContentType モデルです。 ContentType のインスタンスは、プロジェクトにインストールされたモデルに ... 関する情報を表し、格納します。新しい ContentType のインスタンスは、新しいモデルがインストールされるたびに自動的に作成されます。 ContentType のインスタンスは ContentType が ... 表すモデルクラスを返すメソッドと、それらのモデルからオブジェクトを問い合わせるメソッドを持っています。また、 ContentType を操作するためのメソッドや、特定のモデルの ContentType のインスタンスを取得するためのメソッドを追加する カスタムマネージャ ... ... dispatch() head() http_method_not_allowed() setup() TemplateView class TemplateView 属性 (とオプションのアクセサ): content_type extra_context http_method_names response_class [ render_to_response() ] template_engine template_name [ get_template_names ... not_allowed() options() post() put() setup() 詳細ビュー DetailView class DetailView 属性 (とオプションのアクセサ): content_type context_object_name [ get_context_object_name() ] extra_context http_method_names model pk_url_kwarg query_pk_and_slug que ... se() setup() リストビュー ListView class ListView 属性 (とオプションのアクセサ): allow_empty [ get_allow_empty() ] content_type context_object_name [ get_context_object_name() ] extra_context http_method_names model ordering [ get_ordering() ] pagina ... ... を使用します。フォームデータが DEFAULT_CHARSET エンコーディングでないことがわかっている場合に便利です。 HttpRequest. content_type リクエストの MIME タイプを表す文字列です。 CONTENT_TYPE から識別されます。 HttpRequest. content_params CONTENT_TYPE ヘッダ ... です。 HttpRequest. FILES FILES は、アップロードされた全てのファイルを含む辞書型のオブジェクトです。 FILES の各キーは <input type="file" name=""> の name から成ります。 FILES の各値は UploadedFile です。 詳細については、 ファイルの管理 を参照してくださ ... い。 FILES には、リクエストメソッドが POST で、リクエストに投稿した <form> に enctype="multipart/form-data" が設定されていた場合にのみデータが含まれます。それ以外の場合、 FILES は空の辞書のようなオブジェクトに ... ... は True を返します。 クライアントの優先度を考慮して正しいフォーマットを判断するには、 django.http.HttpRequest.get_preferred_type() を使用してください。 class JsonableResponseMixin : """ Mixin to add JSON support to a form. Must be used with an object- ... based FormView (e.g. CreateView). """ accepted_media_types = [ "text/html" , "application/json" ] def dispatch ( self , request , * args , ** kwargs ): if request . get_preferred_t ... ype ( self . accepted_media_types ) is None : # No format in common. return HttpResponse ( status_code = 406 , headers = { "Accept" : "," . join ( self . a ... ... ォルトでは、このフレームワークで作成されたフィードはRSS 2.0を使用します。 これを変更するには、次のように Feed クラスに feed_type 属性を追加します: from django.utils.feedgenerator import Atom1Feed class MyFeed ( Feed ): feed_type = Atom1Feed feed_type ... アイテムごとに1つのエンクロージャのみを持つ場合は代わりに item_enclosure_url 、 item_enclosure_length 、 item_enclosure_mime_type フックを使用します。使用例については、以下の ExampleFeed クラスを参照してください。 言語 Feeds created by the syndication ... フィードの Atom 版と RSS 版の 両方 を利用したい開発者もいるでしょう。そのためには、 Feed クラスのサブクラスを作成し、 feed_type を別のものに設定します。それから URLconf を更新して、追加バージョンを追加します。 すべての例を示します: from django.contri ... 2026年10月08日