{"title":"モデルフィールドリファレンス","version":"1.10","locale":"ja","docname":"ref/models/fields","url":"/ja/1.10/ref/models/fields/","canonical":"https://djangodocs.dev/ja/1.10/ref/models/fields/","summary":"このドキュメントには、Django が提供する field options と field types を含む、Field の全ての API リファレンスが記載されています。","html":"<section id=\"module-django.db.models.fields\">\n<span id=\"model-field-reference\"></span><h1>モデルフィールドリファレンス<a class=\"heading-anchor\" href=\"#module-django.db.models.fields\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h1>\n<p>このドキュメントには、Django が提供する <a class=\"reference internal\" href=\"#field-options\">field options</a> と <a class=\"reference internal\" href=\"#field-types\">field types</a> を含む、<a class=\"reference internal\" href=\"#django.db.models.Field\" title=\"django.db.models.Field\"><code class=\"xref py py-class docutils literal notranslate\">Field</code></a> の全ての API リファレンスが記載されています。</p>\n<aside class=\"admonition admonition-seealso\" role=\"note\">\n<p class=\"admonition-title\">参考</p>\n<p>ビルトインのフィールドがトリックをしない場合、<a class=\"reference external\" href=\"https://github.com/django/django-localflavor\">django-localflavor</a> (<a class=\"reference external\" href=\"https://django-localflavor.readthedocs.io/\">ドキュメント</a>) を試すことができます。これは、特定の国や文化に役立つコードの、分類された場所を含んでいます。</p>\n<p>さらに、簡単に <a class=\"reference internal\" href=\"/ja/1.10/howto/custom-model-fields/\"><span class=\"doc\">あなた自身の独自のモデルフィールドを作ることもできます</span></a>。</p>\n</aside>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">注釈</p>\n<p>技術的には、これらのモデルは <a class=\"reference internal\" href=\"#module-django.db.models.fields\" title=\"django.db.models.fields: Built-in field types.\"><code class=\"xref py py-mod docutils literal notranslate\">django.db.models.fields</code></a> 内で定義されていまが、利便性のため <a class=\"reference internal\" href=\"/ja/1.10/topics/db/models/#module-django.db.models\" title=\"django.db.models\"><code class=\"xref py py-mod docutils literal notranslate\">django.db.models</code></a> にインポートされています; 標準的な慣習では、<code class=\"docutils literal notranslate\">from django.db import models</code> を使って、フィールドを <code class=\"docutils literal notranslate\">models.&lt;Foo&gt;Field</code> として参照します。</p>\n</aside>\n<section id=\"field-options\">\n<span id=\"common-model-field-options\"></span><h2>フィールドオプション<a class=\"heading-anchor\" href=\"#field-options\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>以下の引数は全てのフィールドタイプで有効です。全て省略可能です。</p>\n<section id=\"null\">\n<h3><code class=\"docutils literal notranslate\">null</code><a class=\"heading-anchor\" href=\"#null\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.Field.null\">\n<span class=\"sig-prename descclassname\">Field.</span><span class=\"sig-name descname\">null</span><a class=\"heading-anchor\" href=\"#django.db.models.Field.null\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p><code class=\"docutils literal notranslate\">True``の場合、Django はデータベース内に ``NULL</code> として空の値を保持します。デフォルトは <code class=\"docutils literal notranslate\">False</code> です。</p>\n<p>空の文字列値は常に <code class=\"docutils literal notranslate\">NULL</code> ではなく空の文字列として保持されるため、文字列ベースのフィールド (<a class=\"reference internal\" href=\"#django.db.models.CharField\" title=\"django.db.models.CharField\"><code class=\"xref py py-class docutils literal notranslate\">CharField</code></a> や <a class=\"reference internal\" href=\"#django.db.models.TextField\" title=\"django.db.models.TextField\"><code class=\"xref py py-class docutils literal notranslate\">TextField</code></a>) で <a class=\"reference internal\" href=\"#django.db.models.Field.null\" title=\"django.db.models.Field.null\"><code class=\"xref py py-attr docutils literal notranslate\">null</code></a> を使うことは避けてください。文字列ベースのフィールドが <code class=\"docutils literal notranslate\">null=True</code> を持つ場合、&quot;データなし&quot; に対する 2 種類の値があり得ます: <code class=\"docutils literal notranslate\">NULL</code> と空の文字列です。ほとんどの場合、&quot;データなし&quot; に対して 2 種類の値を持つのは無駄なことです; Django の慣習では、<code class=\"docutils literal notranslate\">NULL</code> ではなく空の文字列を使います。</p>\n<p>文字列ベースと非文字列ベースのフィールドのどちらでも、フォーム内で空の値を許容したい場合には、<code class=\"docutils literal notranslate\">blank=True</code> をセットすることも必要となります。これは、<a class=\"reference internal\" href=\"#django.db.models.Field.null\" title=\"django.db.models.Field.null\"><code class=\"xref py py-attr docutils literal notranslate\">null</code></a> パラメータはデータベーストレー時のみに影響するためです (<a class=\"reference internal\" href=\"#django.db.models.Field.blank\" title=\"django.db.models.Field.blank\"><code class=\"xref py py-attr docutils literal notranslate\">blank</code></a> を参照してください)。</p>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">注釈</p>\n<p>Oracleのデータベースバックエンドを使っているときには、この属性にかかわらず、値 <code class=\"docutils literal notranslate\">NULL</code> が空の文字列を意味するために保持されます。</p>\n</aside>\n<p><a class=\"reference internal\" href=\"#django.db.models.BooleanField\" title=\"django.db.models.BooleanField\"><code class=\"xref py py-class docutils literal notranslate\">BooleanField</code></a> で <a class=\"reference internal\" href=\"#django.db.models.Field.null\" title=\"django.db.models.Field.null\"><code class=\"xref py py-attr docutils literal notranslate\">null</code></a> 値を許容したい場合、代わりに <a class=\"reference internal\" href=\"#django.db.models.NullBooleanField\" title=\"django.db.models.NullBooleanField\"><code class=\"xref py py-class docutils literal notranslate\">NullBooleanField</code></a> を使ってください。</p>\n</section>\n<section id=\"blank\">\n<h3><code class=\"docutils literal notranslate\">blank</code><a class=\"heading-anchor\" href=\"#blank\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.Field.blank\">\n<span class=\"sig-prename descclassname\">Field.</span><span class=\"sig-name descname\">blank</span><a class=\"heading-anchor\" href=\"#django.db.models.Field.blank\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p><code class=\"docutils literal notranslate\">True</code> の場合、フィールドはブランクになることが許容されます。デフォルトは <code class=\"docutils literal notranslate\">False</code> です。</p>\n<p><a class=\"reference internal\" href=\"#django.db.models.Field.null\" title=\"django.db.models.Field.null\"><code class=\"xref py py-attr docutils literal notranslate\">null</code></a> とは異なる点に注意してください。<a class=\"reference internal\" href=\"#django.db.models.Field.null\" title=\"django.db.models.Field.null\"><code class=\"xref py py-attr docutils literal notranslate\">null</code></a> が純粋にデータベースに関連する一方で、<a class=\"reference internal\" href=\"#django.db.models.Field.blank\" title=\"django.db.models.Field.blank\"><code class=\"xref py py-attr docutils literal notranslate\">blank</code></a> はバリデーションに関連します。フィールドが <code class=\"docutils literal notranslate\">blank=True</code> を持つ場合、フォームバリデーションは空の値のエントリーを許容します。<code class=\"docutils literal notranslate\">blank=False</code> を持つ場合、フィールドは必須となります。</p>\n</section>\n<section id=\"choices\">\n<span id=\"field-choices\"></span><h3><code class=\"docutils literal notranslate\">choices</code><a class=\"heading-anchor\" href=\"#choices\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.Field.choices\">\n<span class=\"sig-prename descclassname\">Field.</span><span class=\"sig-name descname\">choices</span><a class=\"heading-anchor\" href=\"#django.db.models.Field.choices\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>フィールドに対する選択肢として使うための 2 項目の iterable 自体で構成される (<code class=\"docutils literal notranslate\">[(A, B), (A, B) ...]</code>) iterable (例: リストやタプル) です。これが与えられた場合は、デフォルトのフォームウィジェットは、標準のテキストフィールドの代わりに、選択肢を伴ったセレクトボックスになります。</p>\n<p>各タプルの最初の要素は、モデル上でセットするための実際の値です。2 番目の要素は人間が読むための名前です。例えば:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code>YEAR_IN_SCHOOL_CHOICES <span class=\"o\">=</span> <span class=\"p\">(</span>\n    <span class=\"p\">(</span><span class=\"s1\">&#39;FR&#39;</span><span class=\"p\">,</span> <span class=\"s1\">&#39;Freshman&#39;</span><span class=\"p\">),</span>\n    <span class=\"p\">(</span><span class=\"s1\">&#39;SO&#39;</span><span class=\"p\">,</span> <span class=\"s1\">&#39;Sophomore&#39;</span><span class=\"p\">),</span>\n    <span class=\"p\">(</span><span class=\"s1\">&#39;JR&#39;</span><span class=\"p\">,</span> <span class=\"s1\">&#39;Junior&#39;</span><span class=\"p\">),</span>\n    <span class=\"p\">(</span><span class=\"s1\">&#39;SR&#39;</span><span class=\"p\">,</span> <span class=\"s1\">&#39;Senior&#39;</span><span class=\"p\">),</span>\n<span class=\"p\">)</span>\n</code></pre></div>\n<p>一般的に、モデルクラスの内部で選択肢を定義し、それぞれの値に適切に名前づけられた定数を定義するのがベストです:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">from</span> <span class=\"nn\">django.db</span> <span class=\"kn\">import</span> models\n\n<span class=\"k\">class</span> <span class=\"nc\">Student</span><span class=\"p\">(</span>models<span class=\"o\">.</span>Model<span class=\"p\">):</span>\n    FRESHMAN <span class=\"o\">=</span> <span class=\"s1\">&#39;FR&#39;</span>\n    SOPHOMORE <span class=\"o\">=</span> <span class=\"s1\">&#39;SO&#39;</span>\n    JUNIOR <span class=\"o\">=</span> <span class=\"s1\">&#39;JR&#39;</span>\n    SENIOR <span class=\"o\">=</span> <span class=\"s1\">&#39;SR&#39;</span>\n    YEAR_IN_SCHOOL_CHOICES <span class=\"o\">=</span> <span class=\"p\">(</span>\n        <span class=\"p\">(</span>FRESHMAN<span class=\"p\">,</span> <span class=\"s1\">&#39;Freshman&#39;</span><span class=\"p\">),</span>\n        <span class=\"p\">(</span>SOPHOMORE<span class=\"p\">,</span> <span class=\"s1\">&#39;Sophomore&#39;</span><span class=\"p\">),</span>\n        <span class=\"p\">(</span>JUNIOR<span class=\"p\">,</span> <span class=\"s1\">&#39;Junior&#39;</span><span class=\"p\">),</span>\n        <span class=\"p\">(</span>SENIOR<span class=\"p\">,</span> <span class=\"s1\">&#39;Senior&#39;</span><span class=\"p\">),</span>\n    <span class=\"p\">)</span>\n    year_in_school <span class=\"o\">=</span> models<span class=\"o\">.</span>CharField<span class=\"p\">(</span>\n        max_length<span class=\"o\">=</span><span class=\"mi\">2</span><span class=\"p\">,</span>\n        choices<span class=\"o\">=</span>YEAR_IN_SCHOOL_CHOICES<span class=\"p\">,</span>\n        default<span class=\"o\">=</span>FRESHMAN<span class=\"p\">,</span>\n    <span class=\"p\">)</span>\n\n    <span class=\"k\">def</span> <span class=\"nf\">is_upperclass</span><span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"p\">):</span>\n        <span class=\"k\">return</span> <span class=\"bp\">self</span><span class=\"o\">.</span>year_in_school <span class=\"ow\">in</span> <span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"o\">.</span>JUNIOR<span class=\"p\">,</span> <span class=\"bp\">self</span><span class=\"o\">.</span>SENIOR<span class=\"p\">)</span>\n</code></pre></div>\n<p>モデルクラスの外部で選択肢のリストを定義して参照することもできますが、モデルの内部でそれぞれの選択肢の値と名前を定義することは、全ての情報をクラスとともに維持し、選択肢を参照しやすくします (例: <code class=\"docutils literal notranslate\">Student.SOPHOMORE</code> は、<code class=\"docutils literal notranslate\">Student</code> モデルがインポートされたあらゆる場所で使うことができます)。</p>\n<p>組織化する目的に使用できる、名前付きグループに利用可能な選択肢を収集することもできます。</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code>MEDIA_CHOICES <span class=\"o\">=</span> <span class=\"p\">(</span>\n    <span class=\"p\">(</span><span class=\"s1\">&#39;Audio&#39;</span><span class=\"p\">,</span> <span class=\"p\">(</span>\n            <span class=\"p\">(</span><span class=\"s1\">&#39;vinyl&#39;</span><span class=\"p\">,</span> <span class=\"s1\">&#39;Vinyl&#39;</span><span class=\"p\">),</span>\n            <span class=\"p\">(</span><span class=\"s1\">&#39;cd&#39;</span><span class=\"p\">,</span> <span class=\"s1\">&#39;CD&#39;</span><span class=\"p\">),</span>\n        <span class=\"p\">)</span>\n    <span class=\"p\">),</span>\n    <span class=\"p\">(</span><span class=\"s1\">&#39;Video&#39;</span><span class=\"p\">,</span> <span class=\"p\">(</span>\n            <span class=\"p\">(</span><span class=\"s1\">&#39;vhs&#39;</span><span class=\"p\">,</span> <span class=\"s1\">&#39;VHS Tape&#39;</span><span class=\"p\">),</span>\n            <span class=\"p\">(</span><span class=\"s1\">&#39;dvd&#39;</span><span class=\"p\">,</span> <span class=\"s1\">&#39;DVD&#39;</span><span class=\"p\">),</span>\n        <span class=\"p\">)</span>\n    <span class=\"p\">),</span>\n    <span class=\"p\">(</span><span class=\"s1\">&#39;unknown&#39;</span><span class=\"p\">,</span> <span class=\"s1\">&#39;Unknown&#39;</span><span class=\"p\">),</span>\n<span class=\"p\">)</span>\n</code></pre></div>\n<p>各タプルの最初の要素はグループに適用するための名前です。2 番目の要素は 2- タプルの iterale です。値とオプションのための人間が読むための名前を含んだ 各 2- タプルを伴います。グループ化されたオプションは、1 つのリストの中でグループ化されていないオプションと結合することができます (例えば、この例の unknown オプションです)。</p>\n<p><a class=\"reference internal\" href=\"#django.db.models.Field.choices\" title=\"django.db.models.Field.choices\"><code class=\"xref py py-attr docutils literal notranslate\">choices</code></a> がセットされているモデルフィールドごとに、Django はフィールドの現在の値に対して人間が読める名前を取得するメソッドを追加します。データベース API ドキュメントの <a class=\"reference internal\" href=\"/ja/1.10/ref/models/instances/#django.db.models.Model.get_FOO_display\" title=\"django.db.models.Model.get_FOO_display\"><code class=\"xref py py-meth docutils literal notranslate\">get_FOO_display()</code></a> を参照してください。</p>\n<p>選択肢はどんな iterable オブジェクトも取り得る -- 必ずしもリストやタプルではない -- ことに注意してください。これにより、選択肢を動的に構成することができます。しかし、<a class=\"reference internal\" href=\"#django.db.models.Field.choices\" title=\"django.db.models.Field.choices\"><code class=\"xref py py-attr docutils literal notranslate\">choices</code></a> を動的にするためいろいろと工夫するぐらいなら、<a class=\"reference internal\" href=\"#django.db.models.ForeignKey\" title=\"django.db.models.ForeignKey\"><code class=\"xref py py-class docutils literal notranslate\">ForeignKey</code></a> を使って適切なデータベーステーブルを使用する方が良いでしょう。 <a class=\"reference internal\" href=\"#django.db.models.Field.choices\" title=\"django.db.models.Field.choices\"><code class=\"xref py py-attr docutils literal notranslate\">choices</code></a> は、ごく稀にしか変化しない静的なデータを意味しています。</p>\n<p><a class=\"reference internal\" href=\"#django.db.models.Field.blank\" title=\"django.db.models.Field.blank\"><code class=\"xref py py-attr docutils literal notranslate\">blank=False</code></a> が <a class=\"reference internal\" href=\"#django.db.models.Field.default\" title=\"django.db.models.Field.default\"><code class=\"xref py py-attr docutils literal notranslate\">default</code></a> とともにフィールド上にセットされない限り、<code class=\"docutils literal notranslate\">&quot;---------&quot;</code> を含むラベルがセレクトボックスに表示されます。この動作をオーバーライドするためには、<code class=\"docutils literal notranslate\">None</code> を含む <code class=\"docutils literal notranslate\">choices</code> にタプルを追加してください; 例えば <code class=\"docutils literal notranslate\">(None, '表示専用の文字列')</code>. もしくは、<code class=\"docutils literal notranslate\">None</code> の代わりに空の文字列を使うこともできます。これは特に <a class=\"reference internal\" href=\"#django.db.models.CharField\" title=\"django.db.models.CharField\"><code class=\"xref py py-class docutils literal notranslate\">CharField</code></a> などに適しています。</p>\n</section>\n<section id=\"db-column\">\n<h3><code class=\"docutils literal notranslate\">db_column</code><a class=\"heading-anchor\" href=\"#db-column\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.Field.db_column\">\n<span class=\"sig-prename descclassname\">Field.</span><span class=\"sig-name descname\">db_column</span><a class=\"heading-anchor\" href=\"#django.db.models.Field.db_column\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>The name of the database column to use for this field. If this isn't given,\nDjango will use the field's name.</p>\n<p>If your database column name is an SQL reserved word, or contains\ncharacters that aren't allowed in Python variable names -- notably, the\nhyphen -- that's OK. Django quotes column and table names behind the\nscenes.</p>\n</section>\n<section id=\"db-index\">\n<h3><code class=\"docutils literal notranslate\">db_index</code><a class=\"heading-anchor\" href=\"#db-index\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.Field.db_index\">\n<span class=\"sig-prename descclassname\">Field.</span><span class=\"sig-name descname\">db_index</span><a class=\"heading-anchor\" href=\"#django.db.models.Field.db_index\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p><code class=\"docutils literal notranslate\">True</code> の場合、データベースインデックスがこのフィールドのために生成されます。</p>\n</section>\n<section id=\"db-tablespace\">\n<h3><code class=\"docutils literal notranslate\">db_tablespace</code><a class=\"heading-anchor\" href=\"#db-tablespace\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.Field.db_tablespace\">\n<span class=\"sig-prename descclassname\">Field.</span><span class=\"sig-name descname\">db_tablespace</span><a class=\"heading-anchor\" href=\"#django.db.models.Field.db_tablespace\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>The name of the <a class=\"reference internal\" href=\"/ja/1.10/topics/db/tablespaces/\"><span class=\"doc\">database tablespace</span></a> to use for\nthis field's index, if this field is indexed. The default is the project's\n<a class=\"reference internal\" href=\"/ja/1.10/ref/settings/#std-setting-DEFAULT_INDEX_TABLESPACE\"><code class=\"xref std std-setting docutils literal notranslate\">DEFAULT_INDEX_TABLESPACE</code></a> setting, if set, or the\n<a class=\"reference internal\" href=\"/ja/1.10/ref/models/options/#django.db.models.Options.db_tablespace\" title=\"django.db.models.Options.db_tablespace\"><code class=\"xref py py-attr docutils literal notranslate\">db_tablespace</code></a> of the model, if any. If the backend doesn't\nsupport tablespaces for indexes, this option is ignored.</p>\n</section>\n<section id=\"default\">\n<h3><code class=\"docutils literal notranslate\">default</code><a class=\"heading-anchor\" href=\"#default\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.Field.default\">\n<span class=\"sig-prename descclassname\">Field.</span><span class=\"sig-name descname\">default</span><a class=\"heading-anchor\" href=\"#django.db.models.Field.default\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>そのフィールドのデフォルト値です。このオプションには特定の値もしくは呼び出し可能オブジェクトを渡すことができます。もし渡した値が呼び出し可能であれば新しくオブジェクトが生成される度に呼び出されます。</p>\n<p>The default can't be a mutable object (model instance, <code class=\"docutils literal notranslate\">list</code>, <code class=\"docutils literal notranslate\">set</code>, etc.),\nas a reference to the same instance of that object would be used as the default\nvalue in all new model instances. Instead, wrap the desired default in a\ncallable. For example, if you want to specify a default <code class=\"docutils literal notranslate\">dict</code> for\n<a class=\"reference internal\" href=\"/ja/1.10/ref/contrib/postgres/fields/#django.contrib.postgres.fields.JSONField\" title=\"django.contrib.postgres.fields.JSONField\"><code class=\"xref py py-class docutils literal notranslate\">JSONField</code></a>, use a function:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"k\">def</span> <span class=\"nf\">contact_default</span><span class=\"p\">():</span>\n    <span class=\"k\">return</span> <span class=\"p\">{</span><span class=\"s2\">&quot;email&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;to1@example.com&quot;</span><span class=\"p\">}</span>\n\ncontact_info <span class=\"o\">=</span> JSONField<span class=\"p\">(</span><span class=\"s2\">&quot;ContactInfo&quot;</span><span class=\"p\">,</span> default<span class=\"o\">=</span>contact_default<span class=\"p\">)</span>\n</code></pre></div>\n<p><code class=\"docutils literal notranslate\">lambda</code>s can't be used for field options like <code class=\"docutils literal notranslate\">default</code> because they\ncan't be <a class=\"reference internal\" href=\"/ja/1.10/topics/migrations/#migration-serializing\"><span class=\"std std-ref\">serialized by migrations</span></a>. See that\ndocumentation for other caveats.</p>\n<p>For fields like <a class=\"reference internal\" href=\"#django.db.models.ForeignKey\" title=\"django.db.models.ForeignKey\"><code class=\"xref py py-class docutils literal notranslate\">ForeignKey</code></a> that map to model instances, defaults\nshould be the value of the field they reference (<code class=\"docutils literal notranslate\">pk</code> unless\n<a class=\"reference internal\" href=\"#django.db.models.ForeignKey.to_field\" title=\"django.db.models.ForeignKey.to_field\"><code class=\"xref py py-attr docutils literal notranslate\">to_field</code></a> is set) instead of model instances.</p>\n<p>The default value is used when new model instances are created and a value\nisn't provided for the field. When the field is a primary key, the default is\nalso used when the field is set to <code class=\"docutils literal notranslate\">None</code>.</p>\n</section>\n<section id=\"editable\">\n<h3><code class=\"docutils literal notranslate\">editable</code><a class=\"heading-anchor\" href=\"#editable\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.Field.editable\">\n<span class=\"sig-prename descclassname\">Field.</span><span class=\"sig-name descname\">editable</span><a class=\"heading-anchor\" href=\"#django.db.models.Field.editable\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>If <code class=\"docutils literal notranslate\">False</code>, the field will not be displayed in the admin or any other\n<a class=\"reference internal\" href=\"/ja/1.10/topics/forms/modelforms/#django.forms.ModelForm\" title=\"django.forms.ModelForm\"><code class=\"xref py py-class docutils literal notranslate\">ModelForm</code></a>. They are also skipped during <a class=\"reference internal\" href=\"/ja/1.10/ref/models/instances/#validating-objects\"><span class=\"std std-ref\">model\nvalidation</span></a>. Default is <code class=\"docutils literal notranslate\">True</code>.</p>\n</section>\n<section id=\"error-messages\">\n<h3><code class=\"docutils literal notranslate\">error_messages</code><a class=\"heading-anchor\" href=\"#error-messages\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.Field.error_messages\">\n<span class=\"sig-prename descclassname\">Field.</span><span class=\"sig-name descname\">error_messages</span><a class=\"heading-anchor\" href=\"#django.db.models.Field.error_messages\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>The <code class=\"docutils literal notranslate\">error_messages</code> argument lets you override the default messages that the\nfield will raise. Pass in a dictionary with keys matching the error messages you\nwant to override.</p>\n<p>Error message keys include <code class=\"docutils literal notranslate\">null</code>, <code class=\"docutils literal notranslate\">blank</code>, <code class=\"docutils literal notranslate\">invalid</code>, <code class=\"docutils literal notranslate\">invalid_choice</code>,\n<code class=\"docutils literal notranslate\">unique</code>, and <code class=\"docutils literal notranslate\">unique_for_date</code>. Additional error message keys are\nspecified for each field in the <a class=\"reference internal\" href=\"#field-types\">Field types</a> section below.</p>\n</section>\n<section id=\"help-text\">\n<h3><code class=\"docutils literal notranslate\">help_text</code><a class=\"heading-anchor\" href=\"#help-text\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.Field.help_text\">\n<span class=\"sig-prename descclassname\">Field.</span><span class=\"sig-name descname\">help_text</span><a class=\"heading-anchor\" href=\"#django.db.models.Field.help_text\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>フォームウィジェットと共に表示される &quot;補助&quot; テキストになります。この値はフィールドがフォームとして利用されない場合でもドキュメント化する際に有用です。</p>\n<p>Note that this value is <em>not</em> HTML-escaped in automatically-generated\nforms. This lets you include HTML in <a class=\"reference internal\" href=\"#django.db.models.Field.help_text\" title=\"django.db.models.Field.help_text\"><code class=\"xref py py-attr docutils literal notranslate\">help_text</code></a> if you so\ndesire. For example:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code>help_text<span class=\"o\">=</span><span class=\"s2\">&quot;Please use the following format: &lt;em&gt;YYYY-MM-DD&lt;/em&gt;.&quot;</span>\n</code></pre></div>\n<p>Alternatively you can use plain text and\n<code class=\"docutils literal notranslate\">django.utils.html.escape()</code> to escape any HTML special characters. Ensure\nthat you escape any help text that may come from untrusted users to avoid a\ncross-site scripting attack.</p>\n</section>\n<section id=\"primary-key\">\n<h3><code class=\"docutils literal notranslate\">primary_key</code><a class=\"heading-anchor\" href=\"#primary-key\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.Field.primary_key\">\n<span class=\"sig-prename descclassname\">Field.</span><span class=\"sig-name descname\">primary_key</span><a class=\"heading-anchor\" href=\"#django.db.models.Field.primary_key\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p><code class=\"docutils literal notranslate\">True</code> の場合、設定したフィールドはそのモデルの主キーとなります。</p>\n<p>If you don't specify <code class=\"docutils literal notranslate\">primary_key=True</code> for any field in your model, Django\nwill automatically add an <a class=\"reference internal\" href=\"#django.db.models.AutoField\" title=\"django.db.models.AutoField\"><code class=\"xref py py-class docutils literal notranslate\">AutoField</code></a> to hold the primary key, so you\ndon't need to set <code class=\"docutils literal notranslate\">primary_key=True</code> on any of your fields unless you want to\noverride the default primary-key behavior. For more, see\n<a class=\"reference internal\" href=\"/ja/1.10/topics/db/models/#automatic-primary-key-fields\"><span class=\"std std-ref\">Automatic primary key fields</span></a>.</p>\n<p><code class=\"docutils literal notranslate\">primary_key=True</code> implies <a class=\"reference internal\" href=\"#django.db.models.Field.null\" title=\"django.db.models.Field.null\"><code class=\"xref py py-attr docutils literal notranslate\">null=False</code></a> and\n<a class=\"reference internal\" href=\"#django.db.models.Field.unique\" title=\"django.db.models.Field.unique\"><code class=\"xref py py-attr docutils literal notranslate\">unique=True</code></a>. Only one primary key is allowed on an\nobject.</p>\n<p>The primary key field is read-only. If you change the value of the primary\nkey on an existing object and then save it, a new object will be created\nalongside the old one.</p>\n</section>\n<section id=\"unique\">\n<h3><code class=\"docutils literal notranslate\">unique</code><a class=\"heading-anchor\" href=\"#unique\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.Field.unique\">\n<span class=\"sig-prename descclassname\">Field.</span><span class=\"sig-name descname\">unique</span><a class=\"heading-anchor\" href=\"#django.db.models.Field.unique\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p><code class=\"docutils literal notranslate\">True</code> の場合、そのフィールドはテーブル上で一意となる制約を受けます。</p>\n<p>This is enforced at the database level and by model validation. If\nyou try to save a model with a duplicate value in a <a class=\"reference internal\" href=\"#django.db.models.Field.unique\" title=\"django.db.models.Field.unique\"><code class=\"xref py py-attr docutils literal notranslate\">unique</code></a>\nfield, a <a class=\"reference internal\" href=\"/ja/1.10/ref/exceptions/#django.db.IntegrityError\" title=\"django.db.IntegrityError\"><code class=\"xref py py-exc docutils literal notranslate\">django.db.IntegrityError</code></a> will be raised by the model's\n<a class=\"reference internal\" href=\"/ja/1.10/ref/models/instances/#django.db.models.Model.save\" title=\"django.db.models.Model.save\"><code class=\"xref py py-meth docutils literal notranslate\">save()</code></a> method.</p>\n<p>This option is valid on all field types except <a class=\"reference internal\" href=\"#django.db.models.ManyToManyField\" title=\"django.db.models.ManyToManyField\"><code class=\"xref py py-class docutils literal notranslate\">ManyToManyField</code></a>,\n<a class=\"reference internal\" href=\"#django.db.models.OneToOneField\" title=\"django.db.models.OneToOneField\"><code class=\"xref py py-class docutils literal notranslate\">OneToOneField</code></a>, and <a class=\"reference internal\" href=\"#django.db.models.FileField\" title=\"django.db.models.FileField\"><code class=\"xref py py-class docutils literal notranslate\">FileField</code></a>.</p>\n<p>Note that when <code class=\"docutils literal notranslate\">unique</code> is <code class=\"docutils literal notranslate\">True</code>, you don't need to specify\n<a class=\"reference internal\" href=\"#django.db.models.Field.db_index\" title=\"django.db.models.Field.db_index\"><code class=\"xref py py-attr docutils literal notranslate\">db_index</code></a>, because <code class=\"docutils literal notranslate\">unique</code> implies the creation of an index.</p>\n</section>\n<section id=\"unique-for-date\">\n<h3><code class=\"docutils literal notranslate\">unique_for_date</code><a class=\"heading-anchor\" href=\"#unique-for-date\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.Field.unique_for_date\">\n<span class=\"sig-prename descclassname\">Field.</span><span class=\"sig-name descname\">unique_for_date</span><a class=\"heading-anchor\" href=\"#django.db.models.Field.unique_for_date\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>Set this to the name of a <a class=\"reference internal\" href=\"#django.db.models.DateField\" title=\"django.db.models.DateField\"><code class=\"xref py py-class docutils literal notranslate\">DateField</code></a> or <a class=\"reference internal\" href=\"#django.db.models.DateTimeField\" title=\"django.db.models.DateTimeField\"><code class=\"xref py py-class docutils literal notranslate\">DateTimeField</code></a> to\nrequire that this field be unique for the value of the date field.</p>\n<p>For example, if you have a field <code class=\"docutils literal notranslate\">title</code> that has\n<code class=\"docutils literal notranslate\">unique_for_date=&quot;pub_date&quot;</code>, then Django wouldn't allow the entry of two\nrecords with the same <code class=\"docutils literal notranslate\">title</code> and <code class=\"docutils literal notranslate\">pub_date</code>.</p>\n<p>Note that if you set this to point to a <a class=\"reference internal\" href=\"#django.db.models.DateTimeField\" title=\"django.db.models.DateTimeField\"><code class=\"xref py py-class docutils literal notranslate\">DateTimeField</code></a>, only the date\nportion of the field will be considered. Besides, when <a class=\"reference internal\" href=\"/ja/1.10/ref/settings/#std-setting-USE_TZ\"><code class=\"xref std std-setting docutils literal notranslate\">USE_TZ</code></a> is\n<code class=\"docutils literal notranslate\">True</code>, the check will be performed in the <a class=\"reference internal\" href=\"/ja/1.10/topics/i18n/timezones/#default-current-time-zone\"><span class=\"std std-ref\">current time zone</span></a> at the time the object gets saved.</p>\n<p>This is enforced by <a class=\"reference internal\" href=\"/ja/1.10/ref/models/instances/#django.db.models.Model.validate_unique\" title=\"django.db.models.Model.validate_unique\"><code class=\"xref py py-meth docutils literal notranslate\">Model.validate_unique()</code></a> during model validation\nbut not at the database level. If any <a class=\"reference internal\" href=\"#django.db.models.Field.unique_for_date\" title=\"django.db.models.Field.unique_for_date\"><code class=\"xref py py-attr docutils literal notranslate\">unique_for_date</code></a> constraint\ninvolves fields that are not part of a <a class=\"reference internal\" href=\"/ja/1.10/topics/forms/modelforms/#django.forms.ModelForm\" title=\"django.forms.ModelForm\"><code class=\"xref py py-class docutils literal notranslate\">ModelForm</code></a> (for\nexample, if one of the fields is listed in <code class=\"docutils literal notranslate\">exclude</code> or has\n<a class=\"reference internal\" href=\"#django.db.models.Field.editable\" title=\"django.db.models.Field.editable\"><code class=\"xref py py-attr docutils literal notranslate\">editable=False</code></a>), <a class=\"reference internal\" href=\"/ja/1.10/ref/models/instances/#django.db.models.Model.validate_unique\" title=\"django.db.models.Model.validate_unique\"><code class=\"xref py py-meth docutils literal notranslate\">Model.validate_unique()</code></a> will\nskip validation for that particular constraint.</p>\n</section>\n<section id=\"unique-for-month\">\n<h3><code class=\"docutils literal notranslate\">unique_for_month</code><a class=\"heading-anchor\" href=\"#unique-for-month\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.Field.unique_for_month\">\n<span class=\"sig-prename descclassname\">Field.</span><span class=\"sig-name descname\">unique_for_month</span><a class=\"heading-anchor\" href=\"#django.db.models.Field.unique_for_month\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>Like <a class=\"reference internal\" href=\"#django.db.models.Field.unique_for_date\" title=\"django.db.models.Field.unique_for_date\"><code class=\"xref py py-attr docutils literal notranslate\">unique_for_date</code></a>, but requires the field to be unique with\nrespect to the month.</p>\n</section>\n<section id=\"unique-for-year\">\n<h3><code class=\"docutils literal notranslate\">unique_for_year</code><a class=\"heading-anchor\" href=\"#unique-for-year\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.Field.unique_for_year\">\n<span class=\"sig-prename descclassname\">Field.</span><span class=\"sig-name descname\">unique_for_year</span><a class=\"heading-anchor\" href=\"#django.db.models.Field.unique_for_year\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>Like <a class=\"reference internal\" href=\"#django.db.models.Field.unique_for_date\" title=\"django.db.models.Field.unique_for_date\"><code class=\"xref py py-attr docutils literal notranslate\">unique_for_date</code></a> and <a class=\"reference internal\" href=\"#django.db.models.Field.unique_for_month\" title=\"django.db.models.Field.unique_for_month\"><code class=\"xref py py-attr docutils literal notranslate\">unique_for_month</code></a>.</p>\n</section>\n<section id=\"verbose-name\">\n<h3><code class=\"docutils literal notranslate\">verbose_name</code><a class=\"heading-anchor\" href=\"#verbose-name\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.Field.verbose_name\">\n<span class=\"sig-prename descclassname\">Field.</span><span class=\"sig-name descname\">verbose_name</span><a class=\"heading-anchor\" href=\"#django.db.models.Field.verbose_name\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>A human-readable name for the field. If the verbose name isn't given, Django\nwill automatically create it using the field's attribute name, converting\nunderscores to spaces. See <a class=\"reference internal\" href=\"/ja/1.10/topics/db/models/#verbose-field-names\"><span class=\"std std-ref\">Verbose field names</span></a>.</p>\n</section>\n<section id=\"validators\">\n<h3><code class=\"docutils literal notranslate\">validators</code><a class=\"heading-anchor\" href=\"#validators\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.Field.validators\">\n<span class=\"sig-prename descclassname\">Field.</span><span class=\"sig-name descname\">validators</span><a class=\"heading-anchor\" href=\"#django.db.models.Field.validators\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>A list of validators to run for this field. See the <a class=\"reference internal\" href=\"/ja/1.10/ref/validators/\"><span class=\"doc\">validators\ndocumentation</span></a> for more information.</p>\n<section id=\"registering-and-fetching-lookups\">\n<h4>Registering and fetching lookups<a class=\"heading-anchor\" href=\"#registering-and-fetching-lookups\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p><code class=\"docutils literal notranslate\">Field</code> implements the <a class=\"reference internal\" href=\"/ja/1.10/ref/models/lookups/#lookup-registration-api\"><span class=\"std std-ref\">lookup registration API</span></a>.\nThe API can be used to customize which lookups are available for a field class, and\nhow lookups are fetched from a field.</p>\n</section>\n</section>\n</section>\n<section id=\"field-types\">\n<span id=\"model-field-types\"></span><h2>フィールドの型<a class=\"heading-anchor\" href=\"#field-types\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<section id=\"autofield\">\n<h3><code class=\"docutils literal notranslate\">AutoField</code><a class=\"heading-anchor\" href=\"#autofield\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.AutoField\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">AutoField</span><span class=\"sig-paren\">(</span><em class=\"sig-param\"><span class=\"o\">**</span>options</em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.db.models.AutoField\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>利用可能な ID に応じて、自動的にインクリメントする <a class=\"reference internal\" href=\"#django.db.models.IntegerField\" title=\"django.db.models.IntegerField\"><code class=\"xref py py-class docutils literal notranslate\">IntegerField</code></a> です。通常は直接使う必要はありません; 指定しない場合は、主キーのフィールドが自動的にモデルに追加されます。<a class=\"reference internal\" href=\"/ja/1.10/topics/db/models/#automatic-primary-key-fields\"><span class=\"std std-ref\">Automatic primary key fields</span></a> も参照してください。</p>\n</section>\n<section id=\"bigautofield\">\n<h3><code class=\"docutils literal notranslate\">BigAutoField</code><a class=\"heading-anchor\" href=\"#bigautofield\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.BigAutoField\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">BigAutoField</span><span class=\"sig-paren\">(</span><em class=\"sig-param\"><span class=\"o\">**</span>options</em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.db.models.BigAutoField\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<aside class=\"version-note version-added\" data-version=\"1.10\" role=\"note\">\n<p class=\"version-note-title\">New in Django 1.10</p></aside>\n<p>64 ビットの数値です。<code class=\"docutils literal notranslate\">1</code> から <code class=\"docutils literal notranslate\">9223372036854775807</code> までの数を扱える以外は、<a class=\"reference internal\" href=\"#django.db.models.AutoField\" title=\"django.db.models.AutoField\"><code class=\"xref py py-class docutils literal notranslate\">AutoField</code></a> と同じです。</p>\n</section>\n<section id=\"bigintegerfield\">\n<h3><code class=\"docutils literal notranslate\">BigIntegerField</code><a class=\"heading-anchor\" href=\"#bigintegerfield\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.BigIntegerField\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">BigIntegerField</span><span class=\"sig-paren\">(</span><em class=\"sig-param\"><span class=\"o\">**</span>options</em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.db.models.BigIntegerField\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>64 ビットの数値です。<code class=\"docutils literal notranslate\">-9223372036854775808</code> から <code class=\"docutils literal notranslate\">9223372036854775807</code> を扱える以外は <a class=\"reference internal\" href=\"#django.db.models.IntegerField\" title=\"django.db.models.IntegerField\"><code class=\"xref py py-class docutils literal notranslate\">IntegerField</code></a> と同じです。このフィールドのデフォルトのフォームウィジェットは <a class=\"reference internal\" href=\"/ja/1.10/ref/forms/widgets/#django.forms.TextInput\" title=\"django.forms.TextInput\"><code class=\"xref py py-class docutils literal notranslate\">TextInput</code></a> です。</p>\n</section>\n<section id=\"binaryfield\">\n<h3><code class=\"docutils literal notranslate\">BinaryField</code><a class=\"heading-anchor\" href=\"#binaryfield\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.BinaryField\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">BinaryField</span><span class=\"sig-paren\">(</span><em class=\"sig-param\"><span class=\"o\">**</span>options</em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.db.models.BinaryField\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>生のバイナリデータを保持するためのフィールドです。bytes` のアサインメントのみをサポートします。このフィールドには機能制限があります。例えば、<code class=\"docutils literal notranslate\">BinaryField</code> の値でクエリセットをフィルタすることはできません。また、<code class=\"docutils literal notranslate\">BinaryField</code> を <a class=\"reference internal\" href=\"/ja/1.10/topics/forms/modelforms/#django.forms.ModelForm\" title=\"django.forms.ModelForm\"><code class=\"xref py py-class docutils literal notranslate\">ModelForm</code></a> に含めることもできません。</p>\n<aside class=\"admonition-abusing-binaryfield admonition\" role=\"note\">\n<p class=\"admonition-title\"><code class=\"docutils literal notranslate\">BinaryField</code> を誤用する</p>\n<p>ファイルをデータベース内に保持したいと考えるかもしれませんが、これは 99% のケースで不適切な設計だということをよく考えてください。このフィールドは適切な <a class=\"reference internal\" href=\"/ja/1.10/howto/static-files/\"><span class=\"doc\">static files</span></a> の処理の代替では <em>ありません</em>.</p>\n</aside>\n</section>\n<section id=\"booleanfield\">\n<h3><code class=\"docutils literal notranslate\">BooleanField</code><a class=\"heading-anchor\" href=\"#booleanfield\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.BooleanField\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">BooleanField</span><span class=\"sig-paren\">(</span><em class=\"sig-param\"><span class=\"o\">**</span>options</em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.db.models.BooleanField\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>true/false のフィールドです。</p>\n<p>このフィールドのデフォルトのフォームウィジェットは <a class=\"reference internal\" href=\"/ja/1.10/ref/forms/widgets/#django.forms.CheckboxInput\" title=\"django.forms.CheckboxInput\"><code class=\"xref py py-class docutils literal notranslate\">CheckboxInput</code></a> です。</p>\n<p><a class=\"reference internal\" href=\"#django.db.models.Field.null\" title=\"django.db.models.Field.null\"><code class=\"xref py py-attr docutils literal notranslate\">null</code></a> 値を受け入れる必要があるときは、代わりに <a class=\"reference internal\" href=\"#django.db.models.NullBooleanField\" title=\"django.db.models.NullBooleanField\"><code class=\"xref py py-class docutils literal notranslate\">NullBooleanField</code></a> を使ってください。</p>\n<p><a class=\"reference internal\" href=\"#django.db.models.Field.default\" title=\"django.db.models.Field.default\"><code class=\"xref py py-attr docutils literal notranslate\">Field.default</code></a> が定義されていないときの <code class=\"docutils literal notranslate\">BooleanField</code> のデフォルト値は <code class=\"docutils literal notranslate\">None</code> です。</p>\n</section>\n<section id=\"charfield\">\n<h3><code class=\"docutils literal notranslate\">CharField</code><a class=\"heading-anchor\" href=\"#charfield\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.CharField\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">CharField</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">max_length<span class=\"o\">=</span><span class=\"default_value\">None</span></em>, <em class=\"sig-param\"><span class=\"o\">**</span>options</em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.db.models.CharField\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>小 - 大サイズの文字列のフィールドです。</p>\n<p>多量のテキストを扱うときは <a class=\"reference internal\" href=\"#django.db.models.TextField\" title=\"django.db.models.TextField\"><code class=\"xref py py-class docutils literal notranslate\">TextField</code></a> を使ってください。</p>\n<p>このフィールドのデフォルトのフォームウィジェットは <a class=\"reference internal\" href=\"/ja/1.10/ref/forms/widgets/#django.forms.TextInput\" title=\"django.forms.TextInput\"><code class=\"xref py py-class docutils literal notranslate\">TextInput</code></a> です。</p>\n<p><a class=\"reference internal\" href=\"#django.db.models.CharField\" title=\"django.db.models.CharField\"><code class=\"xref py py-class docutils literal notranslate\">CharField</code></a> には追加的な必須の引数があります:</p>\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.CharField.max_length\">\n<span class=\"sig-prename descclassname\">CharField.</span><span class=\"sig-name descname\">max_length</span><a class=\"heading-anchor\" href=\"#django.db.models.CharField.max_length\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>フィールドの (文字列の) 最大文字数です。max_length はデータベースレベルと Django のバリデーションで施行されます。</p>\n</dd></dl>\n\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">注釈</p>\n<p>複数のデータベースバックエンド間で使われるアプリケーションを作る場合は、いくつかのバックエンドで <code class=\"docutils literal notranslate\">max_length</code> に制限があることに注意しなければなりません。詳しくは <a class=\"reference internal\" href=\"/ja/1.10/ref/databases/\"><span class=\"doc\">database backend notes</span></a> を参照してください。</p>\n</aside>\n<aside class=\"admonition-mysql-users admonition\" role=\"note\">\n<p class=\"admonition-title\">MySQL ユーザー</p>\n<p>MySQLdb 1.2.2 と <code class=\"docutils literal notranslate\">utf8_bin</code> の照合 (デフォルトでは <em>ありません</em>) でこのフィールドを使う場合は、いくつか気をつけるべきことがあります。詳しくは <a class=\"reference internal\" href=\"/ja/1.10/ref/databases/#mysql-collation\"><span class=\"std std-ref\">MySQL database notes</span></a> を参照してください。</p>\n</aside>\n</section>\n<section id=\"commaseparatedintegerfield\">\n<h3><code class=\"docutils literal notranslate\">CommaSeparatedIntegerField</code><a class=\"heading-anchor\" href=\"#commaseparatedintegerfield\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.CommaSeparatedIntegerField\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">CommaSeparatedIntegerField</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">max_length<span class=\"o\">=</span><span class=\"default_value\">None</span></em>, <em class=\"sig-param\"><span class=\"o\">**</span>options</em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.db.models.CommaSeparatedIntegerField\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<aside class=\"version-note version-deprecated\" data-version=\"1.9\" role=\"note\">\n<p class=\"version-note-title\">Deprecated since Django 1.9</p><p><span class=\"versionmodified deprecated\">バージョン 1.9 で非推奨: </span>このフィールドは、<code class=\"docutils literal notranslate\">validators=[</code><a class=\"reference internal\" href=\"/ja/1.10/ref/validators/#django.core.validators.validate_comma_separated_integer_list\" title=\"django.core.validators.validate_comma_separated_integer_list\"><code class=\"xref py py-func docutils literal notranslate\">validate_comma_separated_integer_list</code></a><code class=\"docutils literal notranslate\">]</code> を持つ <a class=\"reference internal\" href=\"#django.db.models.CharField\" title=\"django.db.models.CharField\"><code class=\"xref py py-class docutils literal notranslate\">CharField</code></a> が支持されているため、非推奨です。</p>\n</aside>\n<p>カンマによって区切られた数値のフィールドです。<a class=\"reference internal\" href=\"#django.db.models.CharField\" title=\"django.db.models.CharField\"><code class=\"xref py py-class docutils literal notranslate\">CharField</code></a> と同じく、<a class=\"reference internal\" href=\"#django.db.models.CharField.max_length\" title=\"django.db.models.CharField.max_length\"><code class=\"xref py py-attr docutils literal notranslate\">max_length</code></a> 引数が必須で、そこで説明したデータベースの可搬性についての注意を考慮する必要があります。</p>\n</section>\n<section id=\"datefield\">\n<h3><code class=\"docutils literal notranslate\">DateField</code><a class=\"heading-anchor\" href=\"#datefield\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.DateField\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">DateField</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">auto_now<span class=\"o\">=</span><span class=\"default_value\">False</span></em>, <em class=\"sig-param\">auto_now_add<span class=\"o\">=</span><span class=\"default_value\">False</span></em>, <em class=\"sig-param\"><span class=\"o\">**</span>options</em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.db.models.DateField\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>Python で <code class=\"docutils literal notranslate\">datetime.date</code> インスタンスによって表される日付です。多少の追加的な省略可能な引数を持ちます:</p>\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.DateField.auto_now\">\n<span class=\"sig-prename descclassname\">DateField.</span><span class=\"sig-name descname\">auto_now</span><a class=\"heading-anchor\" href=\"#django.db.models.DateField.auto_now\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>オブジェクトが保存される度に自動的に現在の日付をセットします。&quot;最後の変更&quot; タイムスタンプに役立ちます。現在の日付が常に使われる点に注意してください; オーバーライドできる単なるデフォルト値ではありません。</p>\n<p><a class=\"reference internal\" href=\"/ja/1.10/ref/models/instances/#django.db.models.Model.save\" title=\"django.db.models.Model.save\"><code class=\"xref py py-meth docutils literal notranslate\">Model.save()</code></a> が呼ばれたとき、フィールドは自動的に更新されるだけです。<a class=\"reference internal\" href=\"/ja/1.10/ref/models/querysets/#django.db.models.query.QuerySet.update\" title=\"django.db.models.query.QuerySet.update\"><code class=\"xref py py-meth docutils literal notranslate\">QuerySet.update()</code></a> のような別の方法で他のフィールドに更新を加えるとき、フィールドは更新されません。あのように更新の中でフィールドの独自の値を指定できるとしてもです。</p>\n</dd></dl>\n\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.DateField.auto_now_add\">\n<span class=\"sig-prename descclassname\">DateField.</span><span class=\"sig-name descname\">auto_now_add</span><a class=\"heading-anchor\" href=\"#django.db.models.DateField.auto_now_add\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>オブジェクトが最初に作成されるとき、自動的にフィールドに現在の日付をセットします。タイムスタンプの作成に役立ちます。現在の日付が <em>常に</em> 使われる点に注意してください; オーバーライドできる単なるデフォルト値ではありません。たとえオブジェクトを作成するときに値をセットしたとしても無視されます。このフィールドを修正できるようにしておきたい場合は、<code class=\"docutils literal notranslate\">auto_now_add=True</code> の代わりに以下をセットしてください:</p>\n<ul class=\"simple\">\n<li><p><a class=\"reference internal\" href=\"#django.db.models.DateField\" title=\"django.db.models.DateField\"><code class=\"xref py py-class docutils literal notranslate\">DateField</code></a> に対して: <code class=\"docutils literal notranslate\">default=date.today</code> - <a class=\"reference external\" href=\"https://docs.python.org/3/library/datetime.html#datetime.date.today\" title=\"(in Python v3.14)\"><code class=\"xref py py-meth docutils literal notranslate\">datetime.date.today()</code></a> より</p></li>\n<li><p><a class=\"reference internal\" href=\"#django.db.models.DateTimeField\" title=\"django.db.models.DateTimeField\"><code class=\"xref py py-class docutils literal notranslate\">DateTimeField</code></a> に対して: <code class=\"docutils literal notranslate\">default=timezone.now</code> - <a class=\"reference internal\" href=\"/ja/1.10/ref/utils/#django.utils.timezone.now\" title=\"django.utils.timezone.now\"><code class=\"xref py py-func docutils literal notranslate\">django.utils.timezone.now()</code></a> より</p></li>\n</ul>\n</dd></dl>\n\n<p>このフィールドのデフォルトのフォームウィジェットは <a class=\"reference internal\" href=\"/ja/1.10/ref/forms/widgets/#django.forms.TextInput\" title=\"django.forms.TextInput\"><code class=\"xref py py-class docutils literal notranslate\">TextInput</code></a> です。admin は JavaScript カレンダーと &quot;今日&quot; のショートカットを加えます。追加の <code class=\"docutils literal notranslate\">invalid_date</code> エラーメッセージキーを含みます。</p>\n<p>オプション <code class=\"docutils literal notranslate\">auto_now_add</code>、<code class=\"docutils literal notranslate\">auto_now</code>、default` は相互に排他的です。これらのオプションを組み合わせるとエラーが発生します。</p>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">注釈</p>\n<p>現在実装されているように、<code class=\"docutils literal notranslate\">auto_now</code> や <code class=\"docutils literal notranslate\">auto_now_add</code> を <code class=\"docutils literal notranslate\">True</code> にセットすると、フィールドは <code class=\"docutils literal notranslate\">editable=False</code> と <code class=\"docutils literal notranslate\">blank=True</code> にセットされます。</p>\n</aside>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">注釈</p>\n<p>The <code class=\"docutils literal notranslate\">auto_now</code> and <code class=\"docutils literal notranslate\">auto_now_add</code> options will always use the date in\nthe <a class=\"reference internal\" href=\"/ja/1.10/topics/i18n/timezones/#default-current-time-zone\"><span class=\"std std-ref\">default timezone</span></a> at the moment of\ncreation or update. If you need something different, you may want to\nconsider simply using your own callable default or overriding <code class=\"docutils literal notranslate\">save()</code>\ninstead of using <code class=\"docutils literal notranslate\">auto_now</code> or <code class=\"docutils literal notranslate\">auto_now_add</code>; or using a\n<code class=\"docutils literal notranslate\">DateTimeField</code> instead of a <code class=\"docutils literal notranslate\">DateField</code> and deciding how to handle the\nconversion from datetime to date at display time.</p>\n</aside>\n</section>\n<section id=\"datetimefield\">\n<h3><code class=\"docutils literal notranslate\">DateTimeField</code><a class=\"heading-anchor\" href=\"#datetimefield\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.DateTimeField\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">DateTimeField</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">auto_now<span class=\"o\">=</span><span class=\"default_value\">False</span></em>, <em class=\"sig-param\">auto_now_add<span class=\"o\">=</span><span class=\"default_value\">False</span></em>, <em class=\"sig-param\"><span class=\"o\">**</span>options</em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.db.models.DateTimeField\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>Python で <code class=\"docutils literal notranslate\">datetime.datetime</code> インスタンスによって表される日付と時刻です。<a class=\"reference internal\" href=\"#django.db.models.DateField\" title=\"django.db.models.DateField\"><code class=\"xref py py-class docutils literal notranslate\">DateField</code></a> と同じくいくつかの追加的な引数を持ちます:</p>\n<p>このフィールドのデフォルトのフォームウィジェットは単一の <a class=\"reference internal\" href=\"/ja/1.10/ref/forms/widgets/#django.forms.TextInput\" title=\"django.forms.TextInput\"><code class=\"xref py py-class docutils literal notranslate\">TextInput</code></a> です。admin は JavaScript ショートカットとともに 2 つの別々の <a class=\"reference internal\" href=\"/ja/1.10/ref/forms/widgets/#django.forms.TextInput\" title=\"django.forms.TextInput\"><code class=\"xref py py-class docutils literal notranslate\">TextInput</code></a> ウィジェットを使います。</p>\n</section>\n<section id=\"decimalfield\">\n<h3><code class=\"docutils literal notranslate\">DecimalField</code><a class=\"heading-anchor\" href=\"#decimalfield\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.DecimalField\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">DecimalField</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">max_digits<span class=\"o\">=</span><span class=\"default_value\">None</span></em>, <em class=\"sig-param\">decimal_places<span class=\"o\">=</span><span class=\"default_value\">None</span></em>, <em class=\"sig-param\"><span class=\"o\">**</span>options</em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.db.models.DecimalField\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>Python で <a class=\"reference external\" href=\"https://docs.python.org/3/library/decimal.html#decimal.Decimal\" title=\"(in Python v3.14)\"><code class=\"xref py py-class docutils literal notranslate\">Decimal</code></a> インスタンスによって表される固定精度の小数です。2 つの <strong>必須の</strong> 引数があります:</p>\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.DecimalField.max_digits\">\n<span class=\"sig-prename descclassname\">DecimalField.</span><span class=\"sig-name descname\">max_digits</span><a class=\"heading-anchor\" href=\"#django.db.models.DecimalField.max_digits\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>数値内で使える桁数の最大値です。 <code class=\"docutils literal notranslate\">decimal_places</code> 以上でなければならない点に注意してください。</p>\n</dd></dl>\n\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.DecimalField.decimal_places\">\n<span class=\"sig-prename descclassname\">DecimalField.</span><span class=\"sig-name descname\">decimal_places</span><a class=\"heading-anchor\" href=\"#django.db.models.DecimalField.decimal_places\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>数値とともに保持される小数点以下の位の数です。</p>\n</dd></dl>\n\n<p>例えば、小数点以下第2位の精度で <code class=\"docutils literal notranslate\">999</code> までの数値を保持するためには、以下を指定します:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code>models<span class=\"o\">.</span>DecimalField<span class=\"p\">(</span><span class=\"o\">...</span><span class=\"p\">,</span> max_digits<span class=\"o\">=</span><span class=\"mi\">5</span><span class=\"p\">,</span> decimal_places<span class=\"o\">=</span><span class=\"mi\">2</span><span class=\"p\">)</span>\n</code></pre></div>\n<p>小数点以下第10位の精度で約10億までを保持するには:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code>models<span class=\"o\">.</span>DecimalField<span class=\"p\">(</span><span class=\"o\">...</span><span class=\"p\">,</span> max_digits<span class=\"o\">=</span><span class=\"mi\">19</span><span class=\"p\">,</span> decimal_places<span class=\"o\">=</span><span class=\"mi\">10</span><span class=\"p\">)</span>\n</code></pre></div>\n<p>このフィールドのデフォルトのフォームウィジェットは、<a class=\"reference internal\" href=\"/ja/1.10/ref/forms/fields/#django.forms.Field.localize\" title=\"django.forms.Field.localize\"><code class=\"xref py py-attr docutils literal notranslate\">localize</code></a> が <code class=\"docutils literal notranslate\">False</code> のとき <a class=\"reference internal\" href=\"/ja/1.10/ref/forms/widgets/#django.forms.NumberInput\" title=\"django.forms.NumberInput\"><code class=\"xref py py-class docutils literal notranslate\">NumberInput</code></a> で、そうでなければ <a class=\"reference internal\" href=\"/ja/1.10/ref/forms/widgets/#django.forms.TextInput\" title=\"django.forms.TextInput\"><code class=\"xref py py-class docutils literal notranslate\">TextInput</code></a> となります。</p>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">注釈</p>\n<p><a class=\"reference internal\" href=\"#django.db.models.FloatField\" title=\"django.db.models.FloatField\"><code class=\"xref py py-class docutils literal notranslate\">FloatField</code></a> クラスと <a class=\"reference internal\" href=\"#django.db.models.DecimalField\" title=\"django.db.models.DecimalField\"><code class=\"xref py py-class docutils literal notranslate\">DecimalField</code></a> クラスの違いについてより詳しく知りたければ,  <a class=\"reference internal\" href=\"#floatfield-vs-decimalfield\"><span class=\"std std-ref\">FloatField vs. DecimalField</span></a> を参照してください。</p>\n</aside>\n</section>\n<section id=\"durationfield\">\n<h3><code class=\"docutils literal notranslate\">DurationField</code><a class=\"heading-anchor\" href=\"#durationfield\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.DurationField\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">DurationField</span><span class=\"sig-paren\">(</span><em class=\"sig-param\"><span class=\"o\">**</span>options</em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.db.models.DurationField\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>時刻の期間を保持するフィールドで、 Python の <a class=\"reference external\" href=\"https://docs.python.org/3/library/datetime.html#datetime.timedelta\" title=\"(in Python v3.14)\"><code class=\"xref py py-class docutils literal notranslate\">timedelta</code></a> によってモデル化されます。PostgreSQL で使われるときに用いられるデータ型は <code class=\"docutils literal notranslate\">interval</code> で、Oracle でのデータ型は <code class=\"docutils literal notranslate\">INTERVAL DAY(9) TO SECOND(6)``です。 それ以外では、マイクロ秒の ``bigint</code> が使われます。</p>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">注釈</p>\n<p><code class=\"docutils literal notranslate\">DurationField</code> での演算はほとんどの場合で機能します。ただし、PostgreSQL 以外のデータベースでは、<code class=\"docutils literal notranslate\">DurationField</code> の値と <code class=\"docutils literal notranslate\">DateTimeField</code> インスタンス上の演算を比較することは期待通りに機能しません。</p>\n</aside>\n</section>\n<section id=\"emailfield\">\n<h3><code class=\"docutils literal notranslate\">EmailField</code><a class=\"heading-anchor\" href=\"#emailfield\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.EmailField\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">EmailField</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">max_length<span class=\"o\">=</span><span class=\"default_value\">254</span></em>, <em class=\"sig-param\"><span class=\"o\">**</span>options</em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.db.models.EmailField\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>値が有効な E メールアドレスかチェックする <a class=\"reference internal\" href=\"#django.db.models.CharField\" title=\"django.db.models.CharField\"><code class=\"xref py py-class docutils literal notranslate\">CharField</code></a> です。<a class=\"reference internal\" href=\"/ja/1.10/ref/validators/#django.core.validators.EmailValidator\" title=\"django.core.validators.EmailValidator\"><code class=\"xref py py-class docutils literal notranslate\">EmailValidator</code></a> を使ってインプットを検証します。</p>\n</section>\n<section id=\"filefield\">\n<h3><code class=\"docutils literal notranslate\">FileField</code><a class=\"heading-anchor\" href=\"#filefield\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.FileField\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">FileField</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">upload_to<span class=\"o\">=</span><span class=\"default_value\">None</span></em>, <em class=\"sig-param\">max_length<span class=\"o\">=</span><span class=\"default_value\">100</span></em>, <em class=\"sig-param\"><span class=\"o\">**</span>options</em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.db.models.FileField\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>ファイルアップロードのフィールドです。</p>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">注釈</p>\n<p><code class=\"docutils literal notranslate\">primary_key</code> と <code class=\"docutils literal notranslate\">unique</code> 引数はサポートされておらず、使われると <code class=\"docutils literal notranslate\">TypeError</code> が発生します。</p>\n</aside>\n<p>2 つの省略可能な引数があります:</p>\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.FileField.upload_to\">\n<span class=\"sig-prename descclassname\">FileField.</span><span class=\"sig-name descname\">upload_to</span><a class=\"heading-anchor\" href=\"#django.db.models.FileField.upload_to\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>この属性は、アップロードディレクトリとファイル名を設定する方法を提供し、2 つの方法でセットできます。どちらの場合も、値は <a class=\"reference internal\" href=\"/ja/1.10/ref/files/storage/#django.core.files.storage.Storage.save\" title=\"django.core.files.storage.Storage.save\"><code class=\"xref py py-meth docutils literal notranslate\">Storage.save()</code></a> メソッドに渡されます。</p>\n<p>If you specify a string value, it may contain <a class=\"reference external\" href=\"https://docs.python.org/3/library/time.html#time.strftime\" title=\"(in Python v3.14)\"><code class=\"xref py py-func docutils literal notranslate\">strftime()</code></a>\nformatting, which will be replaced by the date/time of the file upload (so\nthat uploaded files don't fill up the given directory). For example:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"k\">class</span> <span class=\"nc\">MyModel</span><span class=\"p\">(</span>models<span class=\"o\">.</span>Model<span class=\"p\">):</span>\n    <span class=\"c1\"># file will be uploaded to MEDIA_ROOT/uploads</span>\n    upload <span class=\"o\">=</span> models<span class=\"o\">.</span>FileField<span class=\"p\">(</span>upload_to<span class=\"o\">=</span><span class=\"s1\">&#39;uploads/&#39;</span><span class=\"p\">)</span>\n    <span class=\"c1\"># or...</span>\n    <span class=\"c1\"># file will be saved to MEDIA_ROOT/uploads/2015/01/30</span>\n    upload <span class=\"o\">=</span> models<span class=\"o\">.</span>FileField<span class=\"p\">(</span>upload_to<span class=\"o\">=</span><span class=\"s1\">&#39;uploads/%Y/%m/</span><span class=\"si\">%d</span><span class=\"s1\">/&#39;</span><span class=\"p\">)</span>\n</code></pre></div>\n<p>If you are using the default\n<a class=\"reference internal\" href=\"/ja/1.10/ref/files/storage/#django.core.files.storage.FileSystemStorage\" title=\"django.core.files.storage.FileSystemStorage\"><code class=\"xref py py-class docutils literal notranslate\">FileSystemStorage</code></a>, the string value\nwill be appended to your <a class=\"reference internal\" href=\"/ja/1.10/ref/settings/#std-setting-MEDIA_ROOT\"><code class=\"xref std std-setting docutils literal notranslate\">MEDIA_ROOT</code></a> path to form the location on\nthe local filesystem where uploaded files will be stored. If you are using\na different storage, check that storage's documentation to see how it\nhandles <code class=\"docutils literal notranslate\">upload_to</code>.</p>\n<p><code class=\"docutils literal notranslate\">upload_to</code> may also be a callable, such as a function. This will be\ncalled to obtain the upload path, including the filename. This callable must\naccept two arguments and return a Unix-style path (with forward slashes)\nto be passed along to the storage system. The two arguments are:</p>\n<div class=\"table-scroll\" role=\"region\" tabindex=\"0\" aria-label=\"Table\"><table class=\"docutils align-default\">\n<thead>\n<tr class=\"row-odd\"><th class=\"head\"><p>Argument</p></th>\n<th class=\"head\"><p>説明</p></th>\n</tr>\n</thead>\n<tbody>\n<tr class=\"row-even\"><td><p><code class=\"docutils literal notranslate\">instance</code></p></td>\n<td><p>An instance of the model where the\n<code class=\"docutils literal notranslate\">FileField</code> is defined. More specifically,\nthis is the particular instance where the\ncurrent file is being attached.</p>\n<p>In most cases, this object will not have been\nsaved to the database yet, so if it uses the\ndefault <code class=\"docutils literal notranslate\">AutoField</code>, <em>it might not yet have a\nvalue for its primary key field</em>.</p>\n</td>\n</tr>\n<tr class=\"row-odd\"><td><p><code class=\"docutils literal notranslate\">filename</code></p></td>\n<td><p>The filename that was originally given to the\nfile. This may or may not be taken into account\nwhen determining the final destination path.</p></td>\n</tr>\n</tbody>\n</table>\n</div>\n<p>For example:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"k\">def</span> <span class=\"nf\">user_directory_path</span><span class=\"p\">(</span>instance<span class=\"p\">,</span> filename<span class=\"p\">):</span>\n    <span class=\"c1\"># file will be uploaded to MEDIA_ROOT/user_&lt;id&gt;/&lt;filename&gt;</span>\n    <span class=\"k\">return</span> <span class=\"s1\">&#39;user_</span><span class=\"si\">{0}</span><span class=\"s1\">/</span><span class=\"si\">{1}</span><span class=\"s1\">&#39;</span><span class=\"o\">.</span>format<span class=\"p\">(</span>instance<span class=\"o\">.</span>user<span class=\"o\">.</span>id<span class=\"p\">,</span> filename<span class=\"p\">)</span>\n\n<span class=\"k\">class</span> <span class=\"nc\">MyModel</span><span class=\"p\">(</span>models<span class=\"o\">.</span>Model<span class=\"p\">):</span>\n    upload <span class=\"o\">=</span> models<span class=\"o\">.</span>FileField<span class=\"p\">(</span>upload_to<span class=\"o\">=</span>user_directory_path<span class=\"p\">)</span>\n</code></pre></div>\n</dd></dl>\n\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.FileField.storage\">\n<span class=\"sig-prename descclassname\">FileField.</span><span class=\"sig-name descname\">storage</span><a class=\"heading-anchor\" href=\"#django.db.models.FileField.storage\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>A storage object, which handles the storage and retrieval of your\nfiles. See <a class=\"reference internal\" href=\"/ja/1.10/topics/files/\"><span class=\"doc\">Managing files</span></a> for details on how to provide this object.</p>\n</dd></dl>\n\n<p>このフィールドのデフォルトのフォームウィジェットは <a class=\"reference internal\" href=\"/ja/1.10/ref/forms/widgets/#django.forms.ClearableFileInput\" title=\"django.forms.ClearableFileInput\"><code class=\"xref py py-class docutils literal notranslate\">ClearableFileInput</code></a> です。</p>\n<p>モデル内で a <a class=\"reference internal\" href=\"#django.db.models.FileField\" title=\"django.db.models.FileField\"><code class=\"xref py py-class docutils literal notranslate\">FileField</code></a> や <a class=\"reference internal\" href=\"#django.db.models.ImageField\" title=\"django.db.models.ImageField\"><code class=\"xref py py-class docutils literal notranslate\">ImageField</code></a> (後述) 使うにはいくつかのステップを取ります:</p>\n<ol class=\"arabic simple\">\n<li><p>設定ファイル内で <a class=\"reference internal\" href=\"/ja/1.10/ref/settings/#std-setting-MEDIA_ROOT\"><code class=\"xref std std-setting docutils literal notranslate\">MEDIA_ROOT</code></a> を指定します。この値は、Django がアップロードされたファイルを置く場所にします (パフォーマン ス上の理由から、ファイルをデータベースに置くことはありません)。 <a class=\"reference internal\" href=\"/ja/1.10/ref/settings/#std-setting-MEDIA_URL\"><code class=\"xref std std-setting docutils literal notranslate\">MEDIA_URL</code></a> をそのディレクトリの公開 URL にします。ディレク トリは Web サーバのユーザアカウントに対して書き込み可能にしておかねばなりません。</p></li>\n<li><p>Add the <a class=\"reference internal\" href=\"#django.db.models.FileField\" title=\"django.db.models.FileField\"><code class=\"xref py py-class docutils literal notranslate\">FileField</code></a> or <a class=\"reference internal\" href=\"#django.db.models.ImageField\" title=\"django.db.models.ImageField\"><code class=\"xref py py-class docutils literal notranslate\">ImageField</code></a> to your model, defining\nthe <a class=\"reference internal\" href=\"#django.db.models.FileField.upload_to\" title=\"django.db.models.FileField.upload_to\"><code class=\"xref py py-attr docutils literal notranslate\">upload_to</code></a> option to specify a subdirectory of\n<a class=\"reference internal\" href=\"/ja/1.10/ref/settings/#std-setting-MEDIA_ROOT\"><code class=\"xref std std-setting docutils literal notranslate\">MEDIA_ROOT</code></a> to use for uploaded files.</p></li>\n<li><p>All that will be stored in your database is a path to the file\n(relative to <a class=\"reference internal\" href=\"/ja/1.10/ref/settings/#std-setting-MEDIA_ROOT\"><code class=\"xref std std-setting docutils literal notranslate\">MEDIA_ROOT</code></a>). You'll most likely want to use the\nconvenience <a class=\"reference internal\" href=\"#django.db.models.fields.files.FieldFile.url\" title=\"django.db.models.fields.files.FieldFile.url\"><code class=\"xref py py-attr docutils literal notranslate\">url</code></a> attribute\nprovided by Django. For example, if your <a class=\"reference internal\" href=\"#django.db.models.ImageField\" title=\"django.db.models.ImageField\"><code class=\"xref py py-class docutils literal notranslate\">ImageField</code></a> is called\n<code class=\"docutils literal notranslate\">mug_shot</code>, you can get the absolute path to your image in a template with\n<code class=\"docutils literal notranslate\">{{ object.mug_shot.url }}</code>.</p></li>\n</ol>\n<p>For example, say your <a class=\"reference internal\" href=\"/ja/1.10/ref/settings/#std-setting-MEDIA_ROOT\"><code class=\"xref std std-setting docutils literal notranslate\">MEDIA_ROOT</code></a> is set to <code class=\"docutils literal notranslate\">'/home/media'</code>, and\n<a class=\"reference internal\" href=\"#django.db.models.FileField.upload_to\" title=\"django.db.models.FileField.upload_to\"><code class=\"xref py py-attr docutils literal notranslate\">upload_to</code></a> is set to <code class=\"docutils literal notranslate\">'photos/%Y/%m/%d'</code>. The <code class=\"docutils literal notranslate\">'%Y/%m/%d'</code>\npart of <a class=\"reference internal\" href=\"#django.db.models.FileField.upload_to\" title=\"django.db.models.FileField.upload_to\"><code class=\"xref py py-attr docutils literal notranslate\">upload_to</code></a> is <a class=\"reference external\" href=\"https://docs.python.org/3/library/time.html#time.strftime\" title=\"(in Python v3.14)\"><code class=\"xref py py-func docutils literal notranslate\">strftime()</code></a> formatting;\n<code class=\"docutils literal notranslate\">'%Y'</code> is the four-digit year, <code class=\"docutils literal notranslate\">'%m'</code> is the two-digit month and <code class=\"docutils literal notranslate\">'%d'</code> is\nthe two-digit day. If you upload a file on Jan. 15, 2007, it will be saved in\nthe directory <code class=\"docutils literal notranslate\">/home/media/photos/2007/01/15</code>.</p>\n<p>If you wanted to retrieve the uploaded file's on-disk filename, or the file's\nsize, you could use the <a class=\"reference internal\" href=\"/ja/1.10/ref/files/file/#django.core.files.File.name\" title=\"django.core.files.File.name\"><code class=\"xref py py-attr docutils literal notranslate\">name</code></a> and\n<a class=\"reference internal\" href=\"/ja/1.10/ref/files/file/#django.core.files.File.size\" title=\"django.core.files.File.size\"><code class=\"xref py py-attr docutils literal notranslate\">size</code></a> attributes respectively; for more\ninformation on the available attributes and methods, see the\n<a class=\"reference internal\" href=\"/ja/1.10/ref/files/file/#django.core.files.File\" title=\"django.core.files.File\"><code class=\"xref py py-class docutils literal notranslate\">File</code></a> class reference and the <a class=\"reference internal\" href=\"/ja/1.10/topics/files/\"><span class=\"doc\">Managing files</span></a>\ntopic guide.</p>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">注釈</p>\n<p>The file is saved as part of saving the model in the database, so the actual\nfile name used on disk cannot be relied on until after the model has been\nsaved.</p>\n</aside>\n<p>The uploaded file's relative URL can be obtained using the\n<a class=\"reference internal\" href=\"#django.db.models.fields.files.FieldFile.url\" title=\"django.db.models.fields.files.FieldFile.url\"><code class=\"xref py py-attr docutils literal notranslate\">url</code></a> attribute. Internally,\nthis calls the <a class=\"reference internal\" href=\"/ja/1.10/ref/files/storage/#django.core.files.storage.Storage.url\" title=\"django.core.files.storage.Storage.url\"><code class=\"xref py py-meth docutils literal notranslate\">url()</code></a> method of the\nunderlying <a class=\"reference internal\" href=\"/ja/1.10/ref/files/storage/#django.core.files.storage.Storage\" title=\"django.core.files.storage.Storage\"><code class=\"xref py py-class docutils literal notranslate\">Storage</code></a> class.</p>\n<p id=\"file-upload-security\">Note that whenever you deal with uploaded files, you should pay close attention\nto where you're uploading them and what type of files they are, to avoid\nsecurity holes. <em>Validate all uploaded files</em> so that you're sure the files are\nwhat you think they are. For example, if you blindly let somebody upload files,\nwithout validation, to a directory that's within your Web server's document\nroot, then somebody could upload a CGI or PHP script and execute that script by\nvisiting its URL on your site. Don't allow that.</p>\n<p>Also note that even an uploaded HTML file, since it can be executed by the\nbrowser (though not by the server), can pose security threats that are\nequivalent to XSS or CSRF attacks.</p>\n<p><a class=\"reference internal\" href=\"#django.db.models.FileField\" title=\"django.db.models.FileField\"><code class=\"xref py py-class docutils literal notranslate\">FileField</code></a> instances are created in your database as <code class=\"docutils literal notranslate\">varchar</code>\ncolumns with a default max length of 100 characters. As with other fields, you\ncan change the maximum length using the <a class=\"reference internal\" href=\"#django.db.models.CharField.max_length\" title=\"django.db.models.CharField.max_length\"><code class=\"xref py py-attr docutils literal notranslate\">max_length</code></a> argument.</p>\n<section id=\"filefield-and-fieldfile\">\n<h4><code class=\"docutils literal notranslate\">FileField</code> と <code class=\"docutils literal notranslate\">FieldFile</code><a class=\"heading-anchor\" href=\"#filefield-and-fieldfile\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.fields.files.FieldFile\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">FieldFile</span><a class=\"heading-anchor\" href=\"#django.db.models.fields.files.FieldFile\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>モデル上の <a class=\"reference internal\" href=\"#django.db.models.FileField\" title=\"django.db.models.FileField\"><code class=\"xref py py-class docutils literal notranslate\">FileField</code></a> にアクセスするとき、元となるファイルにアアクセスするためのプロキシとして、<a class=\"reference internal\" href=\"#django.db.models.fields.files.FieldFile\" title=\"django.db.models.fields.files.FieldFile\"><code class=\"xref py py-class docutils literal notranslate\">FieldFile</code></a> のインスタンスが与えられます。</p>\n<p><a class=\"reference internal\" href=\"#django.db.models.fields.files.FieldFile\" title=\"django.db.models.fields.files.FieldFile\"><code class=\"xref py py-class docutils literal notranslate\">FieldFile</code></a>  の API は <a class=\"reference internal\" href=\"/ja/1.10/ref/files/file/#django.core.files.File\" title=\"django.core.files.File\"><code class=\"xref py py-class docutils literal notranslate\">File</code></a> の API を反映していますが、主な違いが 1 つあります: <em>クラスによってラップされたオブジェクトは必ずしも Python のビルトインのファイルオブジェクトのラッパーであるとは限りません。</em> 代わりに、<a class=\"reference internal\" href=\"/ja/1.10/ref/files/storage/#django.core.files.storage.Storage.open\" title=\"django.core.files.storage.Storage.open\"><code class=\"xref py py-attr docutils literal notranslate\">Storage.open()</code></a> メソッドの結果を包むラッパーで、これは  <a class=\"reference internal\" href=\"/ja/1.10/ref/files/file/#django.core.files.File\" title=\"django.core.files.File\"><code class=\"xref py py-class docutils literal notranslate\">File</code></a> オブジェクトもしくは <a class=\"reference internal\" href=\"/ja/1.10/ref/files/file/#django.core.files.File\" title=\"django.core.files.File\"><code class=\"xref py py-class docutils literal notranslate\">File</code></a> API の独自ストレージの実装となります。</p>\n<p>class:~django.core.files.File から継承する API (<a class=\"reference internal\" href=\"/ja/1.10/ref/files/file/#django.core.files.File.read\" title=\"django.core.files.File.read\"><code class=\"xref py py-meth docutils literal notranslate\">read()</code></a> や <a class=\"reference internal\" href=\"/ja/1.10/ref/files/file/#django.core.files.File.write\" title=\"django.core.files.File.write\"><code class=\"xref py py-meth docutils literal notranslate\">write()</code></a>) に加えて、<a class=\"reference internal\" href=\"#django.db.models.fields.files.FieldFile\" title=\"django.db.models.fields.files.FieldFile\"><code class=\"xref py py-class docutils literal notranslate\">FieldFile</code></a> 元となるファイルと相互にやりとりするための複数のメソッドを含んでいます:</p>\n<aside class=\"admonition admonition-warning\" role=\"note\">\n<p class=\"admonition-title\">警告</p>\n<p>このクラスの 2 つのメソッド、<a class=\"reference internal\" href=\"#django.db.models.fields.files.FieldFile.save\" title=\"django.db.models.fields.files.FieldFile.save\"><code class=\"xref py py-meth docutils literal notranslate\">save()</code></a> と <a class=\"reference internal\" href=\"#django.db.models.fields.files.FieldFile.delete\" title=\"django.db.models.fields.files.FieldFile.delete\"><code class=\"xref py py-meth docutils literal notranslate\">delete()</code></a> は、デフォルトで、関連する FieldFile のモデルオブジェクトをデータベースに保存します。</p>\n</aside>\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.fields.files.FieldFile.name\">\n<span class=\"sig-prename descclassname\">FieldFile.</span><span class=\"sig-name descname\">name</span><a class=\"heading-anchor\" href=\"#django.db.models.fields.files.FieldFile.name\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>関連する <a class=\"reference internal\" href=\"#django.db.models.FileField\" title=\"django.db.models.FileField\"><code class=\"xref py py-class docutils literal notranslate\">FileField</code></a> の <a class=\"reference internal\" href=\"/ja/1.10/ref/files/storage/#django.core.files.storage.Storage\" title=\"django.core.files.storage.Storage\"><code class=\"xref py py-class docutils literal notranslate\">Storage</code></a> のルートからの相対パスを含むファイル名です。</p>\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.fields.files.FieldFile.size\">\n<span class=\"sig-prename descclassname\">FieldFile.</span><span class=\"sig-name descname\">size</span><a class=\"heading-anchor\" href=\"#django.db.models.fields.files.FieldFile.size\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>元となる <a class=\"reference internal\" href=\"/ja/1.10/ref/files/storage/#django.core.files.storage.Storage.size\" title=\"django.core.files.storage.Storage.size\"><code class=\"xref py py-attr docutils literal notranslate\">Storage.size()</code></a> メソッドの結果です。</p>\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.fields.files.FieldFile.url\">\n<span class=\"sig-prename descclassname\">FieldFile.</span><span class=\"sig-name descname\">url</span><a class=\"heading-anchor\" href=\"#django.db.models.fields.files.FieldFile.url\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>元となる <a class=\"reference internal\" href=\"/ja/1.10/ref/files/storage/#django.core.files.storage.Storage\" title=\"django.core.files.storage.Storage\"><code class=\"xref py py-class docutils literal notranslate\">Storage</code></a> クラス の <a class=\"reference internal\" href=\"/ja/1.10/ref/files/storage/#django.core.files.storage.Storage.url\" title=\"django.core.files.storage.Storage.url\"><code class=\"xref py py-meth docutils literal notranslate\">url()</code></a> メソッドを呼ぶことによって、ファイルの相対 URL にアクセスするための読み取り専用プロパティです。</p>\n<dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.fields.files.FieldFile.open\">\n<span class=\"sig-prename descclassname\">FieldFile.</span><span class=\"sig-name descname\">open</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">mode<span class=\"o\">=</span><span class=\"default_value\">'rb'</span></em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.db.models.fields.files.FieldFile.open\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>このインスタンスに関連付けられたファイルを、指定された <code class=\"docutils literal notranslate\">モード</code> で開くか、開き直します。標準の Python の <code class=\"docutils literal notranslate\">open()</code> メソッドとは違い、ファイルのデスクリプタを返しません。</p>\n<p>元となるファイルはアクセスするときに暗黙的に開かれるので、元となるファイルにポインタをリセットするためか <code class=\"docutils literal notranslate\">モード</code> を変更するため以外には、このメソッドを呼ぶ必要はないでしょう。</p>\n<dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.fields.files.FieldFile.close\">\n<span class=\"sig-prename descclassname\">FieldFile.</span><span class=\"sig-name descname\">close</span><span class=\"sig-paren\">(</span><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.db.models.fields.files.FieldFile.close\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>標準の Python の <code class=\"docutils literal notranslate\">file.close()</code> メソッドのように動作し、このインスタンスに関連付けられたファイルを閉じます。</p>\n<dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.fields.files.FieldFile.save\">\n<span class=\"sig-prename descclassname\">FieldFile.</span><span class=\"sig-name descname\">save</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">name</em>, <em class=\"sig-param\">content</em>, <em class=\"sig-param\">save<span class=\"o\">=</span><span class=\"default_value\">True</span></em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.db.models.fields.files.FieldFile.save\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>このメソッドは、ファイル名とファイルの内容を取り、それらをフィールドのストレージクラスに渡し、格納されたファイルをモデルフィールドに関連付けます。 手動でファイルデータをモデル上の FileField インスタンスに関連付けるには、<code class=\"docutils literal notranslate\">save()</code> メソッドを使用してそのファイルデータを保持します。</p>\n<p>2 つの必要な引数をとります: <code class=\"docutils literal notranslate\">name</code> はファイルの名前で、<code class=\"docutils literal notranslate\">content</code> はファイルの内容を含むオブジェクトです。 省略可能な <code class=\"docutils literal notranslate\">save</code> 引数は、このフィールドに関連付けられたファイルが変更された後にモデルインスタンスが保存されるかどうかをコントロールします。 デフォルトは <code class=\"docutils literal notranslate\">True</code> です。</p>\n<p><code class=\"docutils literal notranslate\">content</code> 引数は、Python のビルトインのファイルオブジェクトではなく、<a class=\"reference internal\" href=\"/ja/1.10/ref/files/file/#django.core.files.File\" title=\"django.core.files.File\"><code class=\"xref py py-class docutils literal notranslate\">django.core.files.File</code></a> のインスタンスでなければならないことに注意してください。 以下のように、既存の Python ファイルオブジェクトから <a class=\"reference internal\" href=\"/ja/1.10/ref/files/file/#django.core.files.File\" title=\"django.core.files.File\"><code class=\"xref py py-class docutils literal notranslate\">File</code></a> を構築することができます:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">from</span> <span class=\"nn\">django.core.files</span> <span class=\"kn\">import</span> File\n<span class=\"c1\"># Open an existing file using Python&#39;s built-in open()</span>\nf <span class=\"o\">=</span> <span class=\"nb\">open</span><span class=\"p\">(</span><span class=\"s1\">&#39;/path/to/hello.world&#39;</span><span class=\"p\">)</span>\nmyfile <span class=\"o\">=</span> File<span class=\"p\">(</span>f<span class=\"p\">)</span>\n</code></pre></div>\n<p>もしくは、以下のように Python の文字列から構築することもできます:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">from</span> <span class=\"nn\">django.core.files.base</span> <span class=\"kn\">import</span> ContentFile\nmyfile <span class=\"o\">=</span> ContentFile<span class=\"p\">(</span><span class=\"s2\">&quot;hello world&quot;</span><span class=\"p\">)</span>\n</code></pre></div>\n<p>より詳しくは <a class=\"reference internal\" href=\"/ja/1.10/topics/files/\"><span class=\"doc\">Managing files</span></a> をご覧ください。</p>\n<dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.fields.files.FieldFile.delete\">\n<span class=\"sig-prename descclassname\">FieldFile.</span><span class=\"sig-name descname\">delete</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">save<span class=\"o\">=</span><span class=\"default_value\">True</span></em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.db.models.fields.files.FieldFile.delete\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>このインスタンスに関連付けられているファイルを削除し、フィールドのすべての属性をクリアします。 注: このメソッドは、<code class=\"docutils literal notranslate\">delete()</code> が呼び出されたときにファイルが開いた場合、ファイルを閉じます。</p>\n<p>省略可能な <code class=\"docutils literal notranslate\">save</code> 引数は、このフィールドに関連付けられたファイルが削除された後にモデルインスタンスを保存するかどうかをコントロールします。 デフォルトは <code class=\"docutils literal notranslate\">True</code> です。</p>\n<p>モデルを削除するとき、関連ファイルは削除されない点に注意してください。 孤立したファイルをクリーンアップする必要がある場合、自分で処理する必要があります (例えば、手動で実行したり、例えば cron などを通して定期的に実行される、独自の管理コマンドです)。</p>\n</section>\n</section>\n<section id=\"filepathfield\">\n<h3><code class=\"docutils literal notranslate\">FilePathField</code><a class=\"heading-anchor\" href=\"#filepathfield\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.FilePathField\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">FilePathField</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">path<span class=\"o\">=</span><span class=\"default_value\">None</span></em>, <em class=\"sig-param\">match<span class=\"o\">=</span><span class=\"default_value\">None</span></em>, <em class=\"sig-param\">recursive<span class=\"o\">=</span><span class=\"default_value\">False</span></em>, <em class=\"sig-param\">max_length<span class=\"o\">=</span><span class=\"default_value\">100</span></em>, <em class=\"sig-param\"><span class=\"o\">**</span>options</em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.db.models.FilePathField\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>ファイルシステム上の特定のディレクトリ内のファイル名に選択肢が制限されている <a class=\"reference internal\" href=\"#django.db.models.CharField\" title=\"django.db.models.CharField\"><code class=\"xref py py-class docutils literal notranslate\">CharField</code></a> です。3 つの特別な引数があり、最初の 1 つは <strong>必須</strong> です:</p>\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.FilePathField.path\">\n<span class=\"sig-prename descclassname\">FilePathField.</span><span class=\"sig-name descname\">path</span><a class=\"heading-anchor\" href=\"#django.db.models.FilePathField.path\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>必須です。<a class=\"reference internal\" href=\"#django.db.models.FilePathField\" title=\"django.db.models.FilePathField\"><code class=\"xref py py-class docutils literal notranslate\">FilePathField</code></a> が選択肢から取得するディレクトリへの、ファイルシステムの絶対パスです。例: <code class=\"docutils literal notranslate\">&quot;/home/images&quot;</code>。</p>\n</dd></dl>\n\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.FilePathField.match\">\n<span class=\"sig-prename descclassname\">FilePathField.</span><span class=\"sig-name descname\">match</span><a class=\"heading-anchor\" href=\"#django.db.models.FilePathField.match\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>省略可能です。正規表現で、文字列として、<a class=\"reference internal\" href=\"#django.db.models.FilePathField\" title=\"django.db.models.FilePathField\"><code class=\"xref py py-class docutils literal notranslate\">FilePathField</code></a> がファイル名をフィルタリングするために使用します。 正規表現は、フルパスではなくベースファイル名に適用される点に注意してください。 例: <code class=\"docutils literal notranslate\">&quot;foo.*\\.txt$&quot;</code>。これは <code class=\"docutils literal notranslate\">foo23.txt</code> とは合致しますが、<code class=\"docutils literal notranslate\">bar.txt</code> や <code class=\"docutils literal notranslate\">foo23.png</code> とは合致しません。</p>\n</dd></dl>\n\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.FilePathField.recursive\">\n<span class=\"sig-prename descclassname\">FilePathField.</span><span class=\"sig-name descname\">recursive</span><a class=\"heading-anchor\" href=\"#django.db.models.FilePathField.recursive\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>省略可能です。<code class=\"docutils literal notranslate\">True</code> か <code class=\"docutils literal notranslate\">False</code> のどちらかを取り、デフォルトは <code class=\"docutils literal notranslate\">False</code> です。<a class=\"reference internal\" href=\"#django.db.models.FilePathField.path\" title=\"django.db.models.FilePathField.path\"><code class=\"xref py py-attr docutils literal notranslate\">path</code></a> の全てのサブディレクトリを含むかどうかを指定します。</p>\n</dd></dl>\n\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.FilePathField.allow_files\">\n<span class=\"sig-prename descclassname\">FilePathField.</span><span class=\"sig-name descname\">allow_files</span><a class=\"heading-anchor\" href=\"#django.db.models.FilePathField.allow_files\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>省略可能です。<code class=\"docutils literal notranslate\">True</code> か <code class=\"docutils literal notranslate\">False</code> を取り、デフォルトは <code class=\"docutils literal notranslate\">True</code> です。指定された場所にあるファイルを含むかどうかを指定します。 これか <a class=\"reference internal\" href=\"#django.db.models.FilePathField.allow_folders\" title=\"django.db.models.FilePathField.allow_folders\"><code class=\"xref py py-attr docutils literal notranslate\">allow_folders</code></a> のどちらかを <code class=\"docutils literal notranslate\">True</code> にする必要があります。</p>\n</dd></dl>\n\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.FilePathField.allow_folders\">\n<span class=\"sig-prename descclassname\">FilePathField.</span><span class=\"sig-name descname\">allow_folders</span><a class=\"heading-anchor\" href=\"#django.db.models.FilePathField.allow_folders\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>省略可能です。<code class=\"docutils literal notranslate\">True</code> か <code class=\"docutils literal notranslate\">False</code> を取り、デフォルトは <code class=\"docutils literal notranslate\">False</code> です。指定した場所にあるフォルダーを含むかどうかを指定します。これか <a class=\"reference internal\" href=\"#django.db.models.FilePathField.allow_files\" title=\"django.db.models.FilePathField.allow_files\"><code class=\"xref py py-attr docutils literal notranslate\">allow_files</code></a> のどちらかを <code class=\"docutils literal notranslate\">True</code> にする必要があります。</p>\n</dd></dl>\n\n<p>もちろん、これらの引数は同時に使うことができます。</p>\n<p>1つの可能性は、フルパスではなく、ベースファイル名に <a class=\"reference internal\" href=\"#django.db.models.FilePathField.match\" title=\"django.db.models.FilePathField.match\"><code class=\"xref py py-attr docutils literal notranslate\">match</code></a> が適用されることです。 したがって、この例:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code>FilePathField<span class=\"p\">(</span>path<span class=\"o\">=</span><span class=\"s2\">&quot;/home/images&quot;</span><span class=\"p\">,</span> match<span class=\"o\">=</span><span class=\"s2\">&quot;foo.*&quot;</span><span class=\"p\">,</span> recursive<span class=\"o\">=</span><span class=\"kc\">True</span><span class=\"p\">)</span>\n</code></pre></div>\n<p>...は、<code class=\"docutils literal notranslate\">/home/images/foo/bar.png</code> ではなく <code class=\"docutils literal notranslate\">/home/images/foo.png</code> とマッチします。これは、<a class=\"reference internal\" href=\"#django.db.models.FilePathField.match\" title=\"django.db.models.FilePathField.match\"><code class=\"xref py py-attr docutils literal notranslate\">match</code></a> がベースのファイル名に適用されるからです (<code class=\"docutils literal notranslate\">foo.png</code> と <code class=\"docutils literal notranslate\">bar.png</code>)。</p>\n<p><a class=\"reference internal\" href=\"#django.db.models.FilePathField\" title=\"django.db.models.FilePathField\"><code class=\"xref py py-class docutils literal notranslate\">FilePathField</code></a> のインスタンスは、デフォルトが最大 100 文字の <code class=\"docutils literal notranslate\">varchar</code> カラムとして、データベース上に生成されます。他のフィールドと同様に、<a class=\"reference internal\" href=\"#django.db.models.CharField.max_length\" title=\"django.db.models.CharField.max_length\"><code class=\"xref py py-attr docutils literal notranslate\">max_length</code></a> 引数を使って最大文字数を変更することができます。</p>\n</section>\n<section id=\"floatfield\">\n<h3><code class=\"docutils literal notranslate\">FloatField</code><a class=\"heading-anchor\" href=\"#floatfield\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.FloatField\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">FloatField</span><span class=\"sig-paren\">(</span><em class=\"sig-param\"><span class=\"o\">**</span>options</em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.db.models.FloatField\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p><code class=\"docutils literal notranslate\">float</code> インスタンスによって表される Python の浮動小数点数です。</p>\n<p>このフィールドのデフォルトのフォームウィジェットは、<a class=\"reference internal\" href=\"/ja/1.10/ref/forms/fields/#django.forms.Field.localize\" title=\"django.forms.Field.localize\"><code class=\"xref py py-attr docutils literal notranslate\">localize</code></a> が <code class=\"docutils literal notranslate\">False</code> のとき <a class=\"reference internal\" href=\"/ja/1.10/ref/forms/widgets/#django.forms.NumberInput\" title=\"django.forms.NumberInput\"><code class=\"xref py py-class docutils literal notranslate\">NumberInput</code></a> で、そうでなければ <a class=\"reference internal\" href=\"/ja/1.10/ref/forms/widgets/#django.forms.TextInput\" title=\"django.forms.TextInput\"><code class=\"xref py py-class docutils literal notranslate\">TextInput</code></a> となります。</p>\n<aside class=\"admonition-floatfield-vs-decimalfield admonition\" id=\"floatfield-vs-decimalfield\" role=\"note\">\n<p class=\"admonition-title\"><code class=\"docutils literal notranslate\">FloatField</code> と <code class=\"docutils literal notranslate\">DecimalField</code> の比較</p>\n<p><a class=\"reference internal\" href=\"#django.db.models.FloatField\" title=\"django.db.models.FloatField\"><code class=\"xref py py-class docutils literal notranslate\">FloatField</code></a> クラスは、<a class=\"reference internal\" href=\"#django.db.models.DecimalField\" title=\"django.db.models.DecimalField\"><code class=\"xref py py-class docutils literal notranslate\">DecimalField</code></a> クラスと混同されることがあります。両方とも実数を表しますが、異なる方法で表現しています。<code class=\"docutils literal notranslate\">FloatField</code> は内部的には Python の <code class=\"docutils literal notranslate\">float</code> 型を使い、<code class=\"docutils literal notranslate\">DecimalField</code> は Python の <code class=\"docutils literal notranslate\">Decimal</code> 型を使います。この 2 つの違いについては、 Python のドキュメント <a class=\"reference external\" href=\"https://docs.python.org/3/library/decimal.html#module-decimal\" title=\"(in Python v3.14)\"><code class=\"xref py py-mod docutils literal notranslate\">decimal</code></a> module を参照してください。</p>\n</aside>\n</section>\n<section id=\"imagefield\">\n<h3><code class=\"docutils literal notranslate\">ImageField</code><a class=\"heading-anchor\" href=\"#imagefield\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.ImageField\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">ImageField</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">upload_to<span class=\"o\">=</span><span class=\"default_value\">None</span></em>, <em class=\"sig-param\">height_field<span class=\"o\">=</span><span class=\"default_value\">None</span></em>, <em class=\"sig-param\">width_field<span class=\"o\">=</span><span class=\"default_value\">None</span></em>, <em class=\"sig-param\">max_length<span class=\"o\">=</span><span class=\"default_value\">100</span></em>, <em class=\"sig-param\"><span class=\"o\">**</span>options</em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.db.models.ImageField\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p><a class=\"reference internal\" href=\"#django.db.models.FileField\" title=\"django.db.models.FileField\"><code class=\"xref py py-class docutils literal notranslate\">FileField</code></a> から全ての属性とメソッドを継承して、さらにアップロードされたオブジェクトが有効な画像であることを検証します。</p>\n<p><a class=\"reference internal\" href=\"#django.db.models.FileField\" title=\"django.db.models.FileField\"><code class=\"xref py py-class docutils literal notranslate\">FileField</code></a> で使える専用の属性に加えて、<a class=\"reference internal\" href=\"#django.db.models.ImageField\" title=\"django.db.models.ImageField\"><code class=\"xref py py-class docutils literal notranslate\">ImageField</code></a> には <code class=\"docutils literal notranslate\">height</code> と <code class=\"docutils literal notranslate\">width</code> 属性があります。</p>\n<p>これらの属性の照会を容易にするために、<a class=\"reference internal\" href=\"#django.db.models.ImageField\" title=\"django.db.models.ImageField\"><code class=\"xref py py-class docutils literal notranslate\">ImageField</code></a> には 2 つの追加的な省略可能な引数があります:</p>\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.ImageField.height_field\">\n<span class=\"sig-prename descclassname\">ImageField.</span><span class=\"sig-name descname\">height_field</span><a class=\"heading-anchor\" href=\"#django.db.models.ImageField.height_field\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>モデルインスタンスが保存される度に画像の高さで自動入力される、モデルフィールドの名前です。</p>\n</dd></dl>\n\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.ImageField.width_field\">\n<span class=\"sig-prename descclassname\">ImageField.</span><span class=\"sig-name descname\">width_field</span><a class=\"heading-anchor\" href=\"#django.db.models.ImageField.width_field\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>モデルインスタンスが保存される度に画像の幅で自動入力される、モデルフィールドの名前です。</p>\n</dd></dl>\n\n<p><a class=\"reference external\" href=\"https://pillow.readthedocs.io/en/latest/\">Pillow</a> ライブラリを必要とします。</p>\n<p><a class=\"reference internal\" href=\"#django.db.models.ImageField\" title=\"django.db.models.ImageField\"><code class=\"xref py py-class docutils literal notranslate\">ImageField</code></a> のインスタンスは、デフォルトが最大 100 文字の <code class=\"docutils literal notranslate\">varchar</code> カラムとして、データベース上に生成されます。他のフィールドと同様に、<a class=\"reference internal\" href=\"#django.db.models.CharField.max_length\" title=\"django.db.models.CharField.max_length\"><code class=\"xref py py-attr docutils literal notranslate\">max_length</code></a> 引数を使って最大文字数を変更することができます。</p>\n<p>このフィールドのデフォルトのフォームウィジェットは <a class=\"reference internal\" href=\"/ja/1.10/ref/forms/widgets/#django.forms.ClearableFileInput\" title=\"django.forms.ClearableFileInput\"><code class=\"xref py py-class docutils literal notranslate\">ClearableFileInput</code></a> です。</p>\n</section>\n<section id=\"integerfield\">\n<h3><code class=\"docutils literal notranslate\">IntegerField</code><a class=\"heading-anchor\" href=\"#integerfield\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.IntegerField\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">IntegerField</span><span class=\"sig-paren\">(</span><em class=\"sig-param\"><span class=\"o\">**</span>options</em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.db.models.IntegerField\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>数値です。<code class=\"docutils literal notranslate\">-2147483648</code> から <code class=\"docutils literal notranslate\">2147483647</code> までの値は、Django でサポートされているデータベース内では安全です。このフィールドのデフォルトのフォームウィジェットは、<a class=\"reference internal\" href=\"/ja/1.10/ref/forms/fields/#django.forms.Field.localize\" title=\"django.forms.Field.localize\"><code class=\"xref py py-attr docutils literal notranslate\">localize</code></a> が <code class=\"docutils literal notranslate\">False</code> のときには <a class=\"reference internal\" href=\"/ja/1.10/ref/forms/widgets/#django.forms.NumberInput\" title=\"django.forms.NumberInput\"><code class=\"xref py py-class docutils literal notranslate\">NumberInput</code></a> で、そうでなければ <a class=\"reference internal\" href=\"/ja/1.10/ref/forms/widgets/#django.forms.TextInput\" title=\"django.forms.TextInput\"><code class=\"xref py py-class docutils literal notranslate\">TextInput</code></a> となります。</p>\n</section>\n<section id=\"genericipaddressfield\">\n<h3><code class=\"docutils literal notranslate\">GenericIPAddressField</code><a class=\"heading-anchor\" href=\"#genericipaddressfield\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.GenericIPAddressField\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">GenericIPAddressField</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">protocol<span class=\"o\">=</span><span class=\"default_value\">'both'</span></em>, <em class=\"sig-param\">unpack_ipv4<span class=\"o\">=</span><span class=\"default_value\">False</span></em>, <em class=\"sig-param\"><span class=\"o\">**</span>options</em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.db.models.GenericIPAddressField\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>IPv4 か IPv6 のアドレスで、文字列フォーマットです (例: <code class=\"docutils literal notranslate\">192.0.2.30</code> ないし <code class=\"docutils literal notranslate\">2a02:42fe::4</code>)。このフィールドのデフォルトのフォームウィジェットは <a class=\"reference internal\" href=\"/ja/1.10/ref/forms/widgets/#django.forms.TextInput\" title=\"django.forms.TextInput\"><code class=\"xref py py-class docutils literal notranslate\">TextInput</code></a> です。</p>\n<p>IPv6 アドレスは、 <span class=\"target\" id=\"index-2\"></span><a class=\"rfc reference external\" href=\"https://datatracker.ietf.org/doc/html/rfc4291.html#section-2.2\"><strong>RFC 4291 Section 2.2</strong></a> section 2.2 (同セクションの paragraph 3 で提案された IPv4 のフォーマットの使用を含む) にしたがって、 <code class=\"docutils literal notranslate\">::ffff:192.0.2.0</code> のように正規化します。たとえば、 <code class=\"docutils literal notranslate\">2001:0::0:01</code> は <code class=\"docutils literal notranslate\">2001::1</code> と正規化され、 <code class=\"docutils literal notranslate\">::ffff:0a0a:0a0a</code> は <code class=\"docutils literal notranslate\">::ffff:10.10.10.10</code> と正規化されます。そして、すべての文字は小文字に変換されます。</p>\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.GenericIPAddressField.protocol\">\n<span class=\"sig-prename descclassname\">GenericIPAddressField.</span><span class=\"sig-name descname\">protocol</span><a class=\"heading-anchor\" href=\"#django.db.models.GenericIPAddressField.protocol\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>有効なインプットを、指定したプロトコルに制限します。 使用可能な値は <code class=\"docutils literal notranslate\">'both'</code> (デフォルト)、<code class=\"docutils literal notranslate\">'IPv4'</code>、<code class=\"docutils literal notranslate\">'IPv6'</code> のどれかです。マッチングは大文字と小文字を区別しません。</p>\n</dd></dl>\n\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.GenericIPAddressField.unpack_ipv4\">\n<span class=\"sig-prename descclassname\">GenericIPAddressField.</span><span class=\"sig-name descname\">unpack_ipv4</span><a class=\"heading-anchor\" href=\"#django.db.models.GenericIPAddressField.unpack_ipv4\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>IPv4 にマッピングされた <code class=\"docutils literal notranslate\">::ffff:192.0.2.1</code> のようなアドレスをアンパックします。このオプションを有効にすると、このアドレスは <code class=\"docutils literal notranslate\">192.0.2.1</code> とアンパックされます。デフォルトは無効です。<code class=\"docutils literal notranslate\">protocol</code> が <code class=\"docutils literal notranslate\">'both'</code> に設定されている場合にだけ使用できます。</p>\n</dd></dl>\n\n<p>ブランク値を要する場合、ブランク値は null として保持されるため、null 値を許容する必要があります。</p>\n</section>\n<section id=\"nullbooleanfield\">\n<h3><code class=\"docutils literal notranslate\">NullBooleanField</code><a class=\"heading-anchor\" href=\"#nullbooleanfield\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.NullBooleanField\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">NullBooleanField</span><span class=\"sig-paren\">(</span><em class=\"sig-param\"><span class=\"o\">**</span>options</em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.db.models.NullBooleanField\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p><a class=\"reference internal\" href=\"#django.db.models.BooleanField\" title=\"django.db.models.BooleanField\"><code class=\"xref py py-class docutils literal notranslate\">BooleanField</code></a> とほぼ同じですが、オプションの 1 つとして <code class=\"docutils literal notranslate\">NULL</code> を許容します。<a class=\"reference internal\" href=\"#django.db.models.BooleanField\" title=\"django.db.models.BooleanField\"><code class=\"xref py py-class docutils literal notranslate\">BooleanField</code></a> を <code class=\"docutils literal notranslate\">null=True</code> で使う代わりにこれを使ってください。このフィールドのデフォルトのフォームウィジェットは <a class=\"reference internal\" href=\"/ja/1.10/ref/forms/widgets/#django.forms.NullBooleanSelect\" title=\"django.forms.NullBooleanSelect\"><code class=\"xref py py-class docutils literal notranslate\">NullBooleanSelect</code></a> です。</p>\n</section>\n<section id=\"positiveintegerfield\">\n<h3><code class=\"docutils literal notranslate\">PositiveIntegerField</code><a class=\"heading-anchor\" href=\"#positiveintegerfield\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.PositiveIntegerField\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">PositiveIntegerField</span><span class=\"sig-paren\">(</span><em class=\"sig-param\"><span class=\"o\">**</span>options</em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.db.models.PositiveIntegerField\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p><a class=\"reference internal\" href=\"#django.db.models.IntegerField\" title=\"django.db.models.IntegerField\"><code class=\"xref py py-class docutils literal notranslate\">IntegerField</code></a> とほぼ同じですが、正の値かゼロ (<code class=\"docutils literal notranslate\">0</code>) でなければなりません。Django によってサポートされる全てのデータベースで、<code class=\"docutils literal notranslate\">0</code> から <code class=\"docutils literal notranslate\">2147483647</code> までの値は安全です。後方互換性の理由から、値 <code class=\"docutils literal notranslate\">0</code> が有効となっています。</p>\n</section>\n<section id=\"positivesmallintegerfield\">\n<h3><code class=\"docutils literal notranslate\">PositiveSmallIntegerField</code><a class=\"heading-anchor\" href=\"#positivesmallintegerfield\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.PositiveSmallIntegerField\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">PositiveSmallIntegerField</span><span class=\"sig-paren\">(</span><em class=\"sig-param\"><span class=\"o\">**</span>options</em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.db.models.PositiveSmallIntegerField\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p><a class=\"reference internal\" href=\"#django.db.models.PositiveIntegerField\" title=\"django.db.models.PositiveIntegerField\"><code class=\"xref py py-class docutils literal notranslate\">PositiveIntegerField</code></a> とほぼ同じですが、特定の (データベースに依存した) ポイントより下の値のみを許容します。Django でサポートされている全てのデータベースで、<code class=\"docutils literal notranslate\">0</code> から <code class=\"docutils literal notranslate\">32767</code> までの値は安全です。</p>\n</section>\n<section id=\"slugfield\">\n<h3><code class=\"docutils literal notranslate\">SlugField</code><a class=\"heading-anchor\" href=\"#slugfield\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.SlugField\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">SlugField</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">max_length<span class=\"o\">=</span><span class=\"default_value\">50</span></em>, <em class=\"sig-param\"><span class=\"o\">**</span>options</em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.db.models.SlugField\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p><a class=\"reference internal\" href=\"/ja/1.10/glossary/#term-slug\"><span class=\"xref std std-term\">Slug</span></a> は新聞の用語です。 スラグは、文字、数字、アンダースコア、またはハイフンのみを含む短いラベルです。 一般的に URL 内で使用されます。</p>\n<p>CharField のように、<a class=\"reference internal\" href=\"#django.db.models.CharField.max_length\" title=\"django.db.models.CharField.max_length\"><code class=\"xref py py-attr docutils literal notranslate\">max_length</code></a> を指定することもできます (データベースの可搬性についてのノートとそのセクションの <a class=\"reference internal\" href=\"#django.db.models.CharField.max_length\" title=\"django.db.models.CharField.max_length\"><code class=\"xref py py-attr docutils literal notranslate\">max_length</code></a> も参照してください)。<a class=\"reference internal\" href=\"#django.db.models.CharField.max_length\" title=\"django.db.models.CharField.max_length\"><code class=\"xref py py-attr docutils literal notranslate\">max_length</code></a> が指定されていないとき、Django はデフォルトの文字数 50 を使います。</p>\n<p>暗黙的に <a class=\"reference internal\" href=\"#django.db.models.Field.db_index\" title=\"django.db.models.Field.db_index\"><code class=\"xref py py-attr docutils literal notranslate\">Field.db_index</code></a> を <code class=\"docutils literal notranslate\">True</code> にセットします。</p>\n<p>It is often useful to automatically prepopulate a SlugField based on the value\nof some other value.  You can do this automatically in the admin using\n<a class=\"reference internal\" href=\"/ja/1.10/ref/contrib/admin/#django.contrib.admin.ModelAdmin.prepopulated_fields\" title=\"django.contrib.admin.ModelAdmin.prepopulated_fields\"><code class=\"xref py py-attr docutils literal notranslate\">prepopulated_fields</code></a>.</p>\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.SlugField.allow_unicode\">\n<span class=\"sig-prename descclassname\">SlugField.</span><span class=\"sig-name descname\">allow_unicode</span><a class=\"heading-anchor\" href=\"#django.db.models.SlugField.allow_unicode\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><aside class=\"version-note version-added\" data-version=\"1.9\" role=\"note\">\n<p class=\"version-note-title\">New in Django 1.9</p></aside>\n<p>If <code class=\"docutils literal notranslate\">True</code>, the field accepts Unicode letters in addition to ASCII\nletters. Defaults to <code class=\"docutils literal notranslate\">False</code>.</p>\n</dd></dl>\n\n</section>\n<section id=\"smallintegerfield\">\n<h3><code class=\"docutils literal notranslate\">SmallIntegerField</code><a class=\"heading-anchor\" href=\"#smallintegerfield\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.SmallIntegerField\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">SmallIntegerField</span><span class=\"sig-paren\">(</span><em class=\"sig-param\"><span class=\"o\">**</span>options</em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.db.models.SmallIntegerField\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p><a class=\"reference internal\" href=\"#django.db.models.IntegerField\" title=\"django.db.models.IntegerField\"><code class=\"xref py py-class docutils literal notranslate\">IntegerField</code></a> とほぼ同じですが、特定の (データベースに依存した) ポイントより下の値のみを許容します。Django でサポートされている全てのデータベースで、<code class=\"docutils literal notranslate\">-32768</code> から <code class=\"docutils literal notranslate\">32767</code> までの値は安全です。</p>\n</section>\n<section id=\"textfield\">\n<h3><code class=\"docutils literal notranslate\">TextField</code><a class=\"heading-anchor\" href=\"#textfield\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.TextField\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">TextField</span><span class=\"sig-paren\">(</span><em class=\"sig-param\"><span class=\"o\">**</span>options</em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.db.models.TextField\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>多量のテキストのフィールドです。このフィールドのデフォルトのフォームウィジェットは  <a class=\"reference internal\" href=\"/ja/1.10/ref/forms/widgets/#django.forms.Textarea\" title=\"django.forms.Textarea\"><code class=\"xref py py-class docutils literal notranslate\">Textarea</code></a> です。</p>\n<p><code class=\"docutils literal notranslate\">max_length</code> 属性を指定した場合、自動生成されたフォームフィールドの <a class=\"reference internal\" href=\"/ja/1.10/ref/forms/widgets/#django.forms.Textarea\" title=\"django.forms.Textarea\"><code class=\"xref py py-class docutils literal notranslate\">Textarea</code></a> ウィジェット内で反映されます。ただし、モデルやデータベースのレベルでは施行されません。そのためには <a class=\"reference internal\" href=\"#django.db.models.CharField\" title=\"django.db.models.CharField\"><code class=\"xref py py-class docutils literal notranslate\">CharField</code></a> を使用してください。</p>\n<aside class=\"admonition-mysql-users admonition\" role=\"note\">\n<p class=\"admonition-title\">MySQL ユーザー</p>\n<p>このフィールドを MySQLdb 1.2.1p2 と <code class=\"docutils literal notranslate\">utf8_bin</code> の照合 (デフォルトでは <em>ありません</em>) で使う場合、いくつか注意すべき点があります。詳しくは <a class=\"reference internal\" href=\"/ja/1.10/ref/databases/#mysql-collation\"><span class=\"std std-ref\">MySQL database notes</span></a> を参照してください。</p>\n</aside>\n</section>\n<section id=\"timefield\">\n<h3><code class=\"docutils literal notranslate\">TimeField</code><a class=\"heading-anchor\" href=\"#timefield\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.TimeField\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">TimeField</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">auto_now<span class=\"o\">=</span><span class=\"default_value\">False</span></em>, <em class=\"sig-param\">auto_now_add<span class=\"o\">=</span><span class=\"default_value\">False</span></em>, <em class=\"sig-param\"><span class=\"o\">**</span>options</em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.db.models.TimeField\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>Python で <code class=\"docutils literal notranslate\">datetime.time</code> インスタンスによって表される時刻です。<a class=\"reference internal\" href=\"#django.db.models.DateField\" title=\"django.db.models.DateField\"><code class=\"xref py py-class docutils literal notranslate\">DateField</code></a> と同じ自動入力されるオプションを受け入れます。</p>\n<p>このフィールドのデフォルトのフォームウィジェットは <a class=\"reference internal\" href=\"/ja/1.10/ref/forms/widgets/#django.forms.TextInput\" title=\"django.forms.TextInput\"><code class=\"xref py py-class docutils literal notranslate\">TextInput</code></a> です。admin がいくつかの JavaScript ショートカットを加えます.</p>\n</section>\n<section id=\"urlfield\">\n<h3><code class=\"docutils literal notranslate\">URLField</code><a class=\"heading-anchor\" href=\"#urlfield\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.URLField\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">URLField</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">max_length<span class=\"o\">=</span><span class=\"default_value\">200</span></em>, <em class=\"sig-param\"><span class=\"o\">**</span>options</em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.db.models.URLField\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>URL のための <a class=\"reference internal\" href=\"#django.db.models.CharField\" title=\"django.db.models.CharField\"><code class=\"xref py py-class docutils literal notranslate\">CharField</code></a> です。</p>\n<p>このフィールドのデフォルトのフォームウィジェットは <a class=\"reference internal\" href=\"/ja/1.10/ref/forms/widgets/#django.forms.TextInput\" title=\"django.forms.TextInput\"><code class=\"xref py py-class docutils literal notranslate\">TextInput</code></a> です。</p>\n<p>全ての <a class=\"reference internal\" href=\"#django.db.models.CharField\" title=\"django.db.models.CharField\"><code class=\"xref py py-class docutils literal notranslate\">CharField</code></a> サブクラスと同じく、<a class=\"reference internal\" href=\"#django.db.models.URLField\" title=\"django.db.models.URLField\"><code class=\"xref py py-class docutils literal notranslate\">URLField</code></a> は省略可能な <a class=\"reference internal\" href=\"#django.db.models.CharField.max_length\" title=\"django.db.models.CharField.max_length\"><code class=\"xref py py-attr docutils literal notranslate\">max_length</code></a> 引数を取ります。<a class=\"reference internal\" href=\"#django.db.models.CharField.max_length\" title=\"django.db.models.CharField.max_length\"><code class=\"xref py py-attr docutils literal notranslate\">max_length</code></a> を指定しない場合、デフォルトの 200 が使われます。</p>\n</section>\n<section id=\"uuidfield\">\n<h3><code class=\"docutils literal notranslate\">UUIDField</code><a class=\"heading-anchor\" href=\"#uuidfield\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.UUIDField\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">UUIDField</span><span class=\"sig-paren\">(</span><em class=\"sig-param\"><span class=\"o\">**</span>options</em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.db.models.UUIDField\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>UUID (Universally Unique Identifier) を保持するためのフィールドです。Python's <a class=\"reference external\" href=\"https://docs.python.org/3/library/uuid.html#uuid.UUID\" title=\"(in Python v3.14)\"><code class=\"xref py py-class docutils literal notranslate\">UUID</code></a> クラスを使います。 PostgreSQL 上で使われるとき、<code class=\"docutils literal notranslate\">uuid</code> データ型の中に保持します。それ以外は <code class=\"docutils literal notranslate\">char(32)</code> の中に保持します。</p>\n<p>UUID は attr:~Field.primary_key に代わる <a class=\"reference internal\" href=\"#django.db.models.AutoField\" title=\"django.db.models.AutoField\"><code class=\"xref py py-class docutils literal notranslate\">AutoField</code></a> への良い選択肢です。 データベースはあなたのための UUID を生成しないため、<a class=\"reference internal\" href=\"#django.db.models.Field.default\" title=\"django.db.models.Field.default\"><code class=\"xref py py-attr docutils literal notranslate\">default</code></a> を使うことが推奨されます:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">import</span> <span class=\"nn\">uuid</span>\n<span class=\"kn\">from</span> <span class=\"nn\">django.db</span> <span class=\"kn\">import</span> models\n\n<span class=\"k\">class</span> <span class=\"nc\">MyUUIDModel</span><span class=\"p\">(</span>models<span class=\"o\">.</span>Model<span class=\"p\">):</span>\n    <span class=\"nb\">id</span> <span class=\"o\">=</span> models<span class=\"o\">.</span>UUIDField<span class=\"p\">(</span>primary_key<span class=\"o\">=</span><span class=\"kc\">True</span><span class=\"p\">,</span> default<span class=\"o\">=</span>uuid<span class=\"o\">.</span>uuid4<span class=\"p\">,</span> editable<span class=\"o\">=</span><span class=\"kc\">False</span><span class=\"p\">)</span>\n    <span class=\"c1\"># other fields</span>\n</code></pre></div>\n<p>Callable (括弧が省略されている場合) は <code class=\"docutils literal notranslate\">UUID</code> のインスタンスではなく、<code class=\"docutils literal notranslate\">default</code> に渡されます。</p>\n</section>\n</section>\n<section id=\"module-django.db.models.fields.related\">\n<span id=\"relationship-fields\"></span><h2>リレーションシップフィールド<a class=\"heading-anchor\" href=\"#module-django.db.models.fields.related\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Djangoは、リレーションを表すフィールドのセットも定義しています。</p>\n<section id=\"foreignkey\">\n<span id=\"ref-foreignkey\"></span><h3><code class=\"docutils literal notranslate\">ForeignKey</code><a class=\"heading-anchor\" href=\"#foreignkey\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.ForeignKey\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">ForeignKey</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">othermodel</em>, <em class=\"sig-param\">on_delete</em>, <em class=\"sig-param\"><span class=\"o\">**</span>options</em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.db.models.ForeignKey\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>多対 1 のリレーションシップです。位置の引数、つまりモデルが関連するクラスが必要です。</p>\n<aside class=\"version-note version-changed\" data-version=\"1.9\" role=\"note\">\n<p class=\"version-note-title\">Changed in Django 1.9</p><p><code class=\"docutils literal notranslate\">on_delete</code> が 2 番目の引数として使用できるようになりました。(以前は、通常はキーワード引数としてのみ渡されていました)。Django 2.0 では必須の引数になる予定です。</p>\n</aside>\n<p id=\"recursive-relationships\">To create a recursive relationship -- an object that has a many-to-one\nrelationship with itself -- use <code class=\"docutils literal notranslate\">models.ForeignKey('self',\non_delete=models.CASCADE)</code>.</p>\n<p id=\"lazy-relationships\">If you need to create a relationship on a model that has not yet been defined,\nyou can use the name of the model, rather than the model object itself:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">from</span> <span class=\"nn\">django.db</span> <span class=\"kn\">import</span> models\n\n<span class=\"k\">class</span> <span class=\"nc\">Car</span><span class=\"p\">(</span>models<span class=\"o\">.</span>Model<span class=\"p\">):</span>\n    manufacturer <span class=\"o\">=</span> models<span class=\"o\">.</span>ForeignKey<span class=\"p\">(</span>\n        <span class=\"s1\">&#39;Manufacturer&#39;</span><span class=\"p\">,</span>\n        on_delete<span class=\"o\">=</span>models<span class=\"o\">.</span>CASCADE<span class=\"p\">,</span>\n    <span class=\"p\">)</span>\n    <span class=\"c1\"># ...</span>\n\n<span class=\"k\">class</span> <span class=\"nc\">Manufacturer</span><span class=\"p\">(</span>models<span class=\"o\">.</span>Model<span class=\"p\">):</span>\n    <span class=\"c1\"># ...</span>\n    <span class=\"k\">pass</span>\n</code></pre></div>\n<p>Relationships defined this way on <a class=\"reference internal\" href=\"/ja/1.10/topics/db/models/#abstract-base-classes\"><span class=\"std std-ref\">abstract models</span></a> are resolved when the model is subclassed as a\nconcrete model and are not relative to the abstract model's <code class=\"docutils literal notranslate\">app_label</code>:</p>\n<figure class=\"code-block code-block-captioned\" data-language=\"default\"><figcaption class=\"code-block-caption\"><code>products/models.py</code></figcaption><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"products/models.py\"><code><span class=\"kn\">from</span> <span class=\"nn\">django.db</span> <span class=\"kn\">import</span> models\n\n<span class=\"k\">class</span> <span class=\"nc\">AbstractCar</span><span class=\"p\">(</span>models<span class=\"o\">.</span>Model<span class=\"p\">):</span>\n    manufacturer <span class=\"o\">=</span> models<span class=\"o\">.</span>ForeignKey<span class=\"p\">(</span><span class=\"s1\">&#39;Manufacturer&#39;</span><span class=\"p\">,</span> on_delete<span class=\"o\">=</span>models<span class=\"o\">.</span>CASCADE<span class=\"p\">)</span>\n\n    <span class=\"k\">class</span> <span class=\"nc\">Meta</span><span class=\"p\">:</span>\n        abstract <span class=\"o\">=</span> <span class=\"kc\">True</span>\n</code></pre></figure>\n<figure class=\"code-block code-block-captioned\" data-language=\"default\"><figcaption class=\"code-block-caption\"><code>production/models.py</code></figcaption><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"production/models.py\"><code><span class=\"kn\">from</span> <span class=\"nn\">django.db</span> <span class=\"kn\">import</span> models\n<span class=\"kn\">from</span> <span class=\"nn\">products.models</span> <span class=\"kn\">import</span> AbstractCar\n\n<span class=\"k\">class</span> <span class=\"nc\">Manufacturer</span><span class=\"p\">(</span>models<span class=\"o\">.</span>Model<span class=\"p\">):</span>\n    <span class=\"k\">pass</span>\n\n<span class=\"k\">class</span> <span class=\"nc\">Car</span><span class=\"p\">(</span>AbstractCar<span class=\"p\">):</span>\n    <span class=\"k\">pass</span>\n\n<span class=\"c1\"># Car.manufacturer will point to `production.Manufacturer` here.</span>\n</code></pre></figure>\n<p>To refer to models defined in another application, you can explicitly specify\na model with the full application label. For example, if the <code class=\"docutils literal notranslate\">Manufacturer</code>\nmodel above is defined in another application called <code class=\"docutils literal notranslate\">production</code>, you'd\nneed to use:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"k\">class</span> <span class=\"nc\">Car</span><span class=\"p\">(</span>models<span class=\"o\">.</span>Model<span class=\"p\">):</span>\n    manufacturer <span class=\"o\">=</span> models<span class=\"o\">.</span>ForeignKey<span class=\"p\">(</span>\n        <span class=\"s1\">&#39;production.Manufacturer&#39;</span><span class=\"p\">,</span>\n        on_delete<span class=\"o\">=</span>models<span class=\"o\">.</span>CASCADE<span class=\"p\">,</span>\n    <span class=\"p\">)</span>\n</code></pre></div>\n<p>This sort of reference can be useful when resolving circular import\ndependencies between two applications.</p>\n<p>A database index is automatically created on the <code class=\"docutils literal notranslate\">ForeignKey</code>. You can\ndisable this by setting <a class=\"reference internal\" href=\"#django.db.models.Field.db_index\" title=\"django.db.models.Field.db_index\"><code class=\"xref py py-attr docutils literal notranslate\">db_index</code></a> to <code class=\"docutils literal notranslate\">False</code>.  You may want to\navoid the overhead of an index if you are creating a foreign key for\nconsistency rather than joins, or if you will be creating an alternative index\nlike a partial or multiple column index.</p>\n<section id=\"database-representation\">\n<h4>Database Representation<a class=\"heading-anchor\" href=\"#database-representation\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>Behind the scenes, Django appends <code class=\"docutils literal notranslate\">&quot;_id&quot;</code> to the field name to create its\ndatabase column name. In the above example, the database table for the <code class=\"docutils literal notranslate\">Car</code>\nmodel will have a <code class=\"docutils literal notranslate\">manufacturer_id</code> column. (You can change this explicitly by\nspecifying <a class=\"reference internal\" href=\"#django.db.models.Field.db_column\" title=\"django.db.models.Field.db_column\"><code class=\"xref py py-attr docutils literal notranslate\">db_column</code></a>) However, your code should never have to\ndeal with the database column name, unless you write custom SQL. You'll always\ndeal with the field names of your model object.</p>\n</section>\n<section id=\"arguments\">\n<span id=\"foreign-key-arguments\"></span><h4>引数<a class=\"heading-anchor\" href=\"#arguments\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p><a class=\"reference internal\" href=\"#django.db.models.ForeignKey\" title=\"django.db.models.ForeignKey\"><code class=\"xref py py-class docutils literal notranslate\">ForeignKey</code></a> accepts other arguments that define the details of how the\nrelation works.</p>\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.ForeignKey.on_delete\">\n<span class=\"sig-prename descclassname\">ForeignKey.</span><span class=\"sig-name descname\">on_delete</span><a class=\"heading-anchor\" href=\"#django.db.models.ForeignKey.on_delete\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>When an object referenced by a <a class=\"reference internal\" href=\"#django.db.models.ForeignKey\" title=\"django.db.models.ForeignKey\"><code class=\"xref py py-class docutils literal notranslate\">ForeignKey</code></a> is deleted, Django will\nemulate the behavior of the SQL constraint specified by the\n<a class=\"reference internal\" href=\"#django.db.models.ForeignKey.on_delete\" title=\"django.db.models.ForeignKey.on_delete\"><code class=\"xref py py-attr docutils literal notranslate\">on_delete</code></a> argument. For example, if you have a nullable\n<a class=\"reference internal\" href=\"#django.db.models.ForeignKey\" title=\"django.db.models.ForeignKey\"><code class=\"xref py py-class docutils literal notranslate\">ForeignKey</code></a> and you want it to be set null when the referenced\nobject is deleted:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code>user <span class=\"o\">=</span> models<span class=\"o\">.</span>ForeignKey<span class=\"p\">(</span>\n    User<span class=\"p\">,</span>\n    models<span class=\"o\">.</span>SET_NULL<span class=\"p\">,</span>\n    blank<span class=\"o\">=</span><span class=\"kc\">True</span><span class=\"p\">,</span>\n    null<span class=\"o\">=</span><span class=\"kc\">True</span><span class=\"p\">,</span>\n<span class=\"p\">)</span>\n</code></pre></div>\n<aside class=\"version-note version-deprecated\" data-version=\"1.9\" role=\"note\">\n<p class=\"version-note-title\">Deprecated since Django 1.9</p><p><span class=\"versionmodified deprecated\">バージョン 1.9 で非推奨: </span><a class=\"reference internal\" href=\"#django.db.models.ForeignKey.on_delete\" title=\"django.db.models.ForeignKey.on_delete\"><code class=\"xref py py-attr docutils literal notranslate\">on_delete</code></a> will become a required argument in Django\n2.0. In older versions it defaults to <code class=\"docutils literal notranslate\">CASCADE</code>.</p>\n</aside>\n</dd></dl>\n\n<p>The possible values for <a class=\"reference internal\" href=\"#django.db.models.ForeignKey.on_delete\" title=\"django.db.models.ForeignKey.on_delete\"><code class=\"xref py py-attr docutils literal notranslate\">on_delete</code></a> are found in\n<a class=\"reference internal\" href=\"/ja/1.10/topics/db/models/#module-django.db.models\" title=\"django.db.models\"><code class=\"xref py py-mod docutils literal notranslate\">django.db.models</code></a>:</p>\n<ul>\n<li><dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.CASCADE\">\n<span class=\"sig-name descname\">CASCADE</span><a class=\"heading-anchor\" href=\"#django.db.models.CASCADE\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Cascade deletes. Django emulates the behavior of the SQL constraint ON\nDELETE CASCADE and also deletes the object containing the ForeignKey.</p>\n</dd></dl>\n\n</li>\n<li><dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.PROTECT\">\n<span class=\"sig-name descname\">PROTECT</span><a class=\"heading-anchor\" href=\"#django.db.models.PROTECT\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Prevent deletion of the referenced object by raising\n<a class=\"reference internal\" href=\"/ja/1.10/ref/exceptions/#django.db.models.ProtectedError\" title=\"django.db.models.ProtectedError\"><code class=\"xref py py-exc docutils literal notranslate\">ProtectedError</code></a>, a subclass of\n<a class=\"reference internal\" href=\"/ja/1.10/ref/exceptions/#django.db.IntegrityError\" title=\"django.db.IntegrityError\"><code class=\"xref py py-exc docutils literal notranslate\">django.db.IntegrityError</code></a>.</p>\n</dd></dl>\n\n</li>\n<li><dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.SET_NULL\">\n<span class=\"sig-name descname\">SET_NULL</span><a class=\"heading-anchor\" href=\"#django.db.models.SET_NULL\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Set the <a class=\"reference internal\" href=\"#django.db.models.ForeignKey\" title=\"django.db.models.ForeignKey\"><code class=\"xref py py-class docutils literal notranslate\">ForeignKey</code></a> null; this is only possible if\n<a class=\"reference internal\" href=\"#django.db.models.Field.null\" title=\"django.db.models.Field.null\"><code class=\"xref py py-attr docutils literal notranslate\">null</code></a> is <code class=\"docutils literal notranslate\">True</code>.</p>\n</dd></dl>\n\n</li>\n<li><dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.SET_DEFAULT\">\n<span class=\"sig-name descname\">SET_DEFAULT</span><a class=\"heading-anchor\" href=\"#django.db.models.SET_DEFAULT\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Set the <a class=\"reference internal\" href=\"#django.db.models.ForeignKey\" title=\"django.db.models.ForeignKey\"><code class=\"xref py py-class docutils literal notranslate\">ForeignKey</code></a> to its default value; a default for the\n<a class=\"reference internal\" href=\"#django.db.models.ForeignKey\" title=\"django.db.models.ForeignKey\"><code class=\"xref py py-class docutils literal notranslate\">ForeignKey</code></a> must be set.</p>\n</dd></dl>\n\n</li>\n<li><dl class=\"py function\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.SET\">\n<span class=\"sig-name descname\">SET</span><span class=\"sig-paren\">(</span><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.db.models.SET\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Set the <a class=\"reference internal\" href=\"#django.db.models.ForeignKey\" title=\"django.db.models.ForeignKey\"><code class=\"xref py py-class docutils literal notranslate\">ForeignKey</code></a> to the value passed to\n<a class=\"reference internal\" href=\"#django.db.models.SET\" title=\"django.db.models.SET\"><code class=\"xref py py-func docutils literal notranslate\">SET()</code></a>, or if a callable is passed in,\nthe result of calling it. In most cases, passing a callable will be\nnecessary to avoid executing queries at the time your models.py is\nimported:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">from</span> <span class=\"nn\">django.conf</span> <span class=\"kn\">import</span> settings\n<span class=\"kn\">from</span> <span class=\"nn\">django.contrib.auth</span> <span class=\"kn\">import</span> get_user_model\n<span class=\"kn\">from</span> <span class=\"nn\">django.db</span> <span class=\"kn\">import</span> models\n\n<span class=\"k\">def</span> <span class=\"nf\">get_sentinel_user</span><span class=\"p\">():</span>\n    <span class=\"k\">return</span> get_user_model<span class=\"p\">()</span><span class=\"o\">.</span>objects<span class=\"o\">.</span>get_or_create<span class=\"p\">(</span>username<span class=\"o\">=</span><span class=\"s1\">&#39;deleted&#39;</span><span class=\"p\">)[</span><span class=\"mi\">0</span><span class=\"p\">]</span>\n\n<span class=\"k\">class</span> <span class=\"nc\">MyModel</span><span class=\"p\">(</span>models<span class=\"o\">.</span>Model<span class=\"p\">):</span>\n    user <span class=\"o\">=</span> models<span class=\"o\">.</span>ForeignKey<span class=\"p\">(</span>\n        settings<span class=\"o\">.</span>AUTH_USER_MODEL<span class=\"p\">,</span>\n        on_delete<span class=\"o\">=</span>models<span class=\"o\">.</span>SET<span class=\"p\">(</span>get_sentinel_user<span class=\"p\">),</span>\n    <span class=\"p\">)</span>\n</code></pre></div>\n</dd></dl>\n\n</li>\n<li><dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.DO_NOTHING\">\n<span class=\"sig-name descname\">DO_NOTHING</span><a class=\"heading-anchor\" href=\"#django.db.models.DO_NOTHING\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Take no action. If your database backend enforces referential\nintegrity, this will cause an <a class=\"reference internal\" href=\"/ja/1.10/ref/exceptions/#django.db.IntegrityError\" title=\"django.db.IntegrityError\"><code class=\"xref py py-exc docutils literal notranslate\">IntegrityError</code></a> unless\nyou manually add an SQL <code class=\"docutils literal notranslate\">ON DELETE</code> constraint to the database field.</p>\n</dd></dl>\n\n</li>\n</ul>\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.ForeignKey.limit_choices_to\">\n<span class=\"sig-prename descclassname\">ForeignKey.</span><span class=\"sig-name descname\">limit_choices_to</span><a class=\"heading-anchor\" href=\"#django.db.models.ForeignKey.limit_choices_to\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Sets a limit to the available choices for this field when this field is\nrendered using a <code class=\"docutils literal notranslate\">ModelForm</code> or the admin (by default, all objects\nin the queryset are available to choose). Either a dictionary, a\n<a class=\"reference internal\" href=\"/ja/1.10/ref/models/querysets/#django.db.models.Q\" title=\"django.db.models.Q\"><code class=\"xref py py-class docutils literal notranslate\">Q</code></a> object, or a callable returning a\ndictionary or <a class=\"reference internal\" href=\"/ja/1.10/ref/models/querysets/#django.db.models.Q\" title=\"django.db.models.Q\"><code class=\"xref py py-class docutils literal notranslate\">Q</code></a> object can be used.</p>\n<p>For example:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code>staff_member <span class=\"o\">=</span> models<span class=\"o\">.</span>ForeignKey<span class=\"p\">(</span>\n    User<span class=\"p\">,</span>\n    on_delete<span class=\"o\">=</span>models<span class=\"o\">.</span>CASCADE<span class=\"p\">,</span>\n    limit_choices_to<span class=\"o\">=</span><span class=\"p\">{</span><span class=\"s1\">&#39;is_staff&#39;</span><span class=\"p\">:</span> <span class=\"kc\">True</span><span class=\"p\">},</span>\n<span class=\"p\">)</span>\n</code></pre></div>\n<p>causes the corresponding field on the <code class=\"docutils literal notranslate\">ModelForm</code> to list only <code class=\"docutils literal notranslate\">Users</code>\nthat have <code class=\"docutils literal notranslate\">is_staff=True</code>. This may be helpful in the Django admin.</p>\n<p>The callable form can be helpful, for instance, when used in conjunction\nwith the Python <code class=\"docutils literal notranslate\">datetime</code> module to limit selections by date range. For\nexample:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"k\">def</span> <span class=\"nf\">limit_pub_date_choices</span><span class=\"p\">():</span>\n    <span class=\"k\">return</span> <span class=\"p\">{</span><span class=\"s1\">&#39;pub_date__lte&#39;</span><span class=\"p\">:</span> datetime<span class=\"o\">.</span>date<span class=\"o\">.</span>utcnow<span class=\"p\">()}</span>\n\nlimit_choices_to <span class=\"o\">=</span> limit_pub_date_choices\n</code></pre></div>\n<p>If <code class=\"docutils literal notranslate\">limit_choices_to</code> is or returns a <a class=\"reference internal\" href=\"/ja/1.10/ref/models/querysets/#django.db.models.Q\" title=\"django.db.models.Q\"><code class=\"xref py py-class docutils literal notranslate\">Q object</code></a>, which is useful for <a class=\"reference internal\" href=\"/ja/1.10/topics/db/queries/#complex-lookups-with-q\"><span class=\"std std-ref\">complex queries</span></a>, then it will only have an effect on the choices\navailable in the admin when the field is not listed in\n<a class=\"reference internal\" href=\"/ja/1.10/ref/contrib/admin/#django.contrib.admin.ModelAdmin.raw_id_fields\" title=\"django.contrib.admin.ModelAdmin.raw_id_fields\"><code class=\"xref py py-attr docutils literal notranslate\">raw_id_fields</code></a> in the\n<code class=\"docutils literal notranslate\">ModelAdmin</code> for the model.</p>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">注釈</p>\n<p>If a callable is used for <code class=\"docutils literal notranslate\">limit_choices_to</code>, it will be invoked\nevery time a new form is instantiated. It may also be invoked when a\nmodel is validated, for example by management commands or the admin.\nThe admin constructs querysets to validate its form inputs in various\nedge cases multiple times, so there is a possibility your callable may\nbe invoked several times.</p>\n</aside>\n</dd></dl>\n\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.ForeignKey.related_name\">\n<span class=\"sig-prename descclassname\">ForeignKey.</span><span class=\"sig-name descname\">related_name</span><a class=\"heading-anchor\" href=\"#django.db.models.ForeignKey.related_name\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>The name to use for the relation from the related object back to this one.\nIt's also the default value for <a class=\"reference internal\" href=\"#django.db.models.ForeignKey.related_query_name\" title=\"django.db.models.ForeignKey.related_query_name\"><code class=\"xref py py-attr docutils literal notranslate\">related_query_name</code></a> (the name to use\nfor the reverse filter name from the target model). See the <a class=\"reference internal\" href=\"/ja/1.10/topics/db/queries/#backwards-related-objects\"><span class=\"std std-ref\">related\nobjects documentation</span></a> for a full explanation\nand example. Note that you must set this value when defining relations on\n<a class=\"reference internal\" href=\"/ja/1.10/topics/db/models/#abstract-base-classes\"><span class=\"std std-ref\">abstract models</span></a>; and when you do so\n<a class=\"reference internal\" href=\"/ja/1.10/topics/db/models/#abstract-related-name\"><span class=\"std std-ref\">some special syntax</span></a> is available.</p>\n<p>If you'd prefer Django not to create a backwards relation, set\n<code class=\"docutils literal notranslate\">related_name</code> to <code class=\"docutils literal notranslate\">'+'</code> or end it with <code class=\"docutils literal notranslate\">'+'</code>. For example, this will\nensure that the <code class=\"docutils literal notranslate\">User</code> model won't have a backwards relation to this\nmodel:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code>user <span class=\"o\">=</span> models<span class=\"o\">.</span>ForeignKey<span class=\"p\">(</span>\n    User<span class=\"p\">,</span>\n    on_delete<span class=\"o\">=</span>models<span class=\"o\">.</span>CASCADE<span class=\"p\">,</span>\n    related_name<span class=\"o\">=</span><span class=\"s1\">&#39;+&#39;</span><span class=\"p\">,</span>\n<span class=\"p\">)</span>\n</code></pre></div>\n</dd></dl>\n\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.ForeignKey.related_query_name\">\n<span class=\"sig-prename descclassname\">ForeignKey.</span><span class=\"sig-name descname\">related_query_name</span><a class=\"heading-anchor\" href=\"#django.db.models.ForeignKey.related_query_name\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>The name to use for the reverse filter name from the target model. It\ndefaults to the value of <a class=\"reference internal\" href=\"#django.db.models.ForeignKey.related_name\" title=\"django.db.models.ForeignKey.related_name\"><code class=\"xref py py-attr docutils literal notranslate\">related_name</code></a> or\n<a class=\"reference internal\" href=\"/ja/1.10/ref/models/options/#django.db.models.Options.default_related_name\" title=\"django.db.models.Options.default_related_name\"><code class=\"xref py py-attr docutils literal notranslate\">default_related_name</code></a> if set, otherwise it\ndefaults to the name of the model:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"c1\"># Declare the ForeignKey with related_query_name</span>\n<span class=\"k\">class</span> <span class=\"nc\">Tag</span><span class=\"p\">(</span>models<span class=\"o\">.</span>Model<span class=\"p\">):</span>\n    article <span class=\"o\">=</span> models<span class=\"o\">.</span>ForeignKey<span class=\"p\">(</span>\n        Article<span class=\"p\">,</span>\n        on_delete<span class=\"o\">=</span>models<span class=\"o\">.</span>CASCADE<span class=\"p\">,</span>\n        related_name<span class=\"o\">=</span><span class=\"s2\">&quot;tags&quot;</span><span class=\"p\">,</span>\n        related_query_name<span class=\"o\">=</span><span class=\"s2\">&quot;tag&quot;</span><span class=\"p\">,</span>\n    <span class=\"p\">)</span>\n    name <span class=\"o\">=</span> models<span class=\"o\">.</span>CharField<span class=\"p\">(</span>max_length<span class=\"o\">=</span><span class=\"mi\">255</span><span class=\"p\">)</span>\n\n<span class=\"c1\"># That&#39;s now the name of the reverse filter</span>\nArticle<span class=\"o\">.</span>objects<span class=\"o\">.</span>filter<span class=\"p\">(</span>tag__name<span class=\"o\">=</span><span class=\"s2\">&quot;important&quot;</span><span class=\"p\">)</span>\n</code></pre></div>\n<p>Like <a class=\"reference internal\" href=\"#django.db.models.ForeignKey.related_name\" title=\"django.db.models.ForeignKey.related_name\"><code class=\"xref py py-attr docutils literal notranslate\">related_name</code></a>, <code class=\"docutils literal notranslate\">related_query_name</code> supports app label and\nclass interpolation via <a class=\"reference internal\" href=\"/ja/1.10/topics/db/models/#abstract-related-name\"><span class=\"std std-ref\">some special syntax</span></a>.</p>\n</dd></dl>\n\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.ForeignKey.to_field\">\n<span class=\"sig-prename descclassname\">ForeignKey.</span><span class=\"sig-name descname\">to_field</span><a class=\"heading-anchor\" href=\"#django.db.models.ForeignKey.to_field\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>The field on the related object that the relation is to. By default, Django\nuses the primary key of the related object. If you reference a different\nfield, that field must have <code class=\"docutils literal notranslate\">unique=True</code>.</p>\n</dd></dl>\n\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.ForeignKey.db_constraint\">\n<span class=\"sig-prename descclassname\">ForeignKey.</span><span class=\"sig-name descname\">db_constraint</span><a class=\"heading-anchor\" href=\"#django.db.models.ForeignKey.db_constraint\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Controls whether or not a constraint should be created in the database for\nthis foreign key. The default is <code class=\"docutils literal notranslate\">True</code>, and that's almost certainly what\nyou want; setting this to <code class=\"docutils literal notranslate\">False</code> can be very bad for data integrity.\nThat said, here are some scenarios where you might want to do this:</p>\n<ul class=\"simple\">\n<li><p>You have legacy data that is not valid.</p></li>\n<li><p>You're sharding your database.</p></li>\n</ul>\n<p>If this is set to <code class=\"docutils literal notranslate\">False</code>, accessing a related object that doesn't exist\nwill raise its <code class=\"docutils literal notranslate\">DoesNotExist</code> exception.</p>\n</dd></dl>\n\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.ForeignKey.swappable\">\n<span class=\"sig-prename descclassname\">ForeignKey.</span><span class=\"sig-name descname\">swappable</span><a class=\"heading-anchor\" href=\"#django.db.models.ForeignKey.swappable\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Controls the migration framework's reaction if this <a class=\"reference internal\" href=\"#django.db.models.ForeignKey\" title=\"django.db.models.ForeignKey\"><code class=\"xref py py-class docutils literal notranslate\">ForeignKey</code></a>\nis pointing at a swappable model. If it is <code class=\"docutils literal notranslate\">True</code> - the default -\nthen if the <a class=\"reference internal\" href=\"#django.db.models.ForeignKey\" title=\"django.db.models.ForeignKey\"><code class=\"xref py py-class docutils literal notranslate\">ForeignKey</code></a> is pointing at a model which matches\nthe current value of <code class=\"docutils literal notranslate\">settings.AUTH_USER_MODEL</code> (or another swappable\nmodel setting) the relationship will be stored in the migration using\na reference to the setting, not to the model directly.</p>\n<p>You only want to override this to be <code class=\"docutils literal notranslate\">False</code> if you are sure your\nmodel should always point towards the swapped-in model - for example,\nif it is a profile model designed specifically for your custom user model.</p>\n<p>Setting it to <code class=\"docutils literal notranslate\">False</code> does not mean you can reference a swappable model\neven if it is swapped out - <code class=\"docutils literal notranslate\">False</code> just means that the migrations made\nwith this ForeignKey will always reference the exact model you specify\n(so it will fail hard if the user tries to run with a User model you don't\nsupport, for example).</p>\n<p>If in doubt, leave it to its default of <code class=\"docutils literal notranslate\">True</code>.</p>\n</dd></dl>\n\n</section>\n</section>\n<section id=\"manytomanyfield\">\n<h3><code class=\"docutils literal notranslate\">ManyToManyField</code><a class=\"heading-anchor\" href=\"#manytomanyfield\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.ManyToManyField\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">ManyToManyField</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">othermodel</em>, <em class=\"sig-param\"><span class=\"o\">**</span>options</em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.db.models.ManyToManyField\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>A many-to-many relationship. Requires a positional argument: the class to\nwhich the model is related, which works exactly the same as it does for\n<a class=\"reference internal\" href=\"#django.db.models.ForeignKey\" title=\"django.db.models.ForeignKey\"><code class=\"xref py py-class docutils literal notranslate\">ForeignKey</code></a>, including <a class=\"reference internal\" href=\"#recursive-relationships\"><span class=\"std std-ref\">recursive</span></a> and\n<a class=\"reference internal\" href=\"#lazy-relationships\"><span class=\"std std-ref\">lazy</span></a> relationships.</p>\n<p>Related objects can be added, removed, or created with the field's\n<a class=\"reference internal\" href=\"/ja/1.10/ref/models/relations/#django.db.models.fields.related.RelatedManager\" title=\"django.db.models.fields.related.RelatedManager\"><code class=\"xref py py-class docutils literal notranslate\">RelatedManager</code></a>.</p>\n<section id=\"id1\">\n<h4>Database Representation<a class=\"heading-anchor\" href=\"#id1\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>Behind the scenes, Django creates an intermediary join table to represent the\nmany-to-many relationship. By default, this table name is generated using the\nname of the many-to-many field and the name of the table for the model that\ncontains it. Since some databases don't support table names above a certain\nlength, these table names will be automatically truncated to 64 characters and a\nuniqueness hash will be used. This means you might see table names like\n<code class=\"docutils literal notranslate\">author_books_9cdf4</code>; this is perfectly normal.  You can manually provide the\nname of the join table using the <a class=\"reference internal\" href=\"#django.db.models.ManyToManyField.db_table\" title=\"django.db.models.ManyToManyField.db_table\"><code class=\"xref py py-attr docutils literal notranslate\">db_table</code></a> option.</p>\n</section>\n<section id=\"manytomany-arguments\">\n<span id=\"id2\"></span><h4>引数<a class=\"heading-anchor\" href=\"#manytomany-arguments\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p><a class=\"reference internal\" href=\"#django.db.models.ManyToManyField\" title=\"django.db.models.ManyToManyField\"><code class=\"xref py py-class docutils literal notranslate\">ManyToManyField</code></a> accepts an extra set of arguments -- all optional --\nthat control how the relationship functions.</p>\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.ManyToManyField.related_name\">\n<span class=\"sig-prename descclassname\">ManyToManyField.</span><span class=\"sig-name descname\">related_name</span><a class=\"heading-anchor\" href=\"#django.db.models.ManyToManyField.related_name\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Same as <a class=\"reference internal\" href=\"#django.db.models.ForeignKey.related_name\" title=\"django.db.models.ForeignKey.related_name\"><code class=\"xref py py-attr docutils literal notranslate\">ForeignKey.related_name</code></a>.</p>\n</dd></dl>\n\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.ManyToManyField.related_query_name\">\n<span class=\"sig-prename descclassname\">ManyToManyField.</span><span class=\"sig-name descname\">related_query_name</span><a class=\"heading-anchor\" href=\"#django.db.models.ManyToManyField.related_query_name\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Same as <a class=\"reference internal\" href=\"#django.db.models.ForeignKey.related_query_name\" title=\"django.db.models.ForeignKey.related_query_name\"><code class=\"xref py py-attr docutils literal notranslate\">ForeignKey.related_query_name</code></a>.</p>\n</dd></dl>\n\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.ManyToManyField.limit_choices_to\">\n<span class=\"sig-prename descclassname\">ManyToManyField.</span><span class=\"sig-name descname\">limit_choices_to</span><a class=\"heading-anchor\" href=\"#django.db.models.ManyToManyField.limit_choices_to\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Same as <a class=\"reference internal\" href=\"#django.db.models.ForeignKey.limit_choices_to\" title=\"django.db.models.ForeignKey.limit_choices_to\"><code class=\"xref py py-attr docutils literal notranslate\">ForeignKey.limit_choices_to</code></a>.</p>\n<p><code class=\"docutils literal notranslate\">limit_choices_to</code> has no effect when used on a <code class=\"docutils literal notranslate\">ManyToManyField</code> with a\ncustom intermediate table specified using the\n<a class=\"reference internal\" href=\"#django.db.models.ManyToManyField.through\" title=\"django.db.models.ManyToManyField.through\"><code class=\"xref py py-attr docutils literal notranslate\">through</code></a> parameter.</p>\n</dd></dl>\n\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.ManyToManyField.symmetrical\">\n<span class=\"sig-prename descclassname\">ManyToManyField.</span><span class=\"sig-name descname\">symmetrical</span><a class=\"heading-anchor\" href=\"#django.db.models.ManyToManyField.symmetrical\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Only used in the definition of ManyToManyFields on self. Consider the\nfollowing model:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">from</span> <span class=\"nn\">django.db</span> <span class=\"kn\">import</span> models\n\n<span class=\"k\">class</span> <span class=\"nc\">Person</span><span class=\"p\">(</span>models<span class=\"o\">.</span>Model<span class=\"p\">):</span>\n    friends <span class=\"o\">=</span> models<span class=\"o\">.</span>ManyToManyField<span class=\"p\">(</span><span class=\"s2\">&quot;self&quot;</span><span class=\"p\">)</span>\n</code></pre></div>\n<p>When Django processes this model, it identifies that it has a\n<a class=\"reference internal\" href=\"#django.db.models.ManyToManyField\" title=\"django.db.models.ManyToManyField\"><code class=\"xref py py-class docutils literal notranslate\">ManyToManyField</code></a> on itself, and as a result, it doesn't add a\n<code class=\"docutils literal notranslate\">person_set</code> attribute to the <code class=\"docutils literal notranslate\">Person</code> class. Instead, the\n<a class=\"reference internal\" href=\"#django.db.models.ManyToManyField\" title=\"django.db.models.ManyToManyField\"><code class=\"xref py py-class docutils literal notranslate\">ManyToManyField</code></a> is assumed to be symmetrical -- that is, if I am\nyour friend, then you are my friend.</p>\n<p>If you do not want symmetry in many-to-many relationships with <code class=\"docutils literal notranslate\">self</code>, set\n<a class=\"reference internal\" href=\"#django.db.models.ManyToManyField.symmetrical\" title=\"django.db.models.ManyToManyField.symmetrical\"><code class=\"xref py py-attr docutils literal notranslate\">symmetrical</code></a> to <code class=\"docutils literal notranslate\">False</code>. This will force Django to\nadd the descriptor for the reverse relationship, allowing\n<a class=\"reference internal\" href=\"#django.db.models.ManyToManyField\" title=\"django.db.models.ManyToManyField\"><code class=\"xref py py-class docutils literal notranslate\">ManyToManyField</code></a> relationships to be non-symmetrical.</p>\n</dd></dl>\n\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.ManyToManyField.through\">\n<span class=\"sig-prename descclassname\">ManyToManyField.</span><span class=\"sig-name descname\">through</span><a class=\"heading-anchor\" href=\"#django.db.models.ManyToManyField.through\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Django will automatically generate a table to manage many-to-many\nrelationships. However, if you want to manually specify the intermediary\ntable, you can use the <a class=\"reference internal\" href=\"#django.db.models.ManyToManyField.through\" title=\"django.db.models.ManyToManyField.through\"><code class=\"xref py py-attr docutils literal notranslate\">through</code></a> option to specify\nthe Django model that represents the intermediate table that you want to\nuse.</p>\n<p>The most common use for this option is when you want to associate\n<a class=\"reference internal\" href=\"/ja/1.10/topics/db/models/#intermediary-manytomany\"><span class=\"std std-ref\">extra data with a many-to-many relationship</span></a>.</p>\n<p>If you don't specify an explicit <code class=\"docutils literal notranslate\">through</code> model, there is still an\nimplicit <code class=\"docutils literal notranslate\">through</code> model class you can use to directly access the table\ncreated to hold the association. It has three fields to link the models.</p>\n<p>If the source and target models differ, the following fields are\ngenerated:</p>\n<ul class=\"simple\">\n<li><p><code class=\"docutils literal notranslate\">id</code>: the primary key of the relation.</p></li>\n<li><p><code class=\"docutils literal notranslate\">&lt;containing_model&gt;_id</code>: the <code class=\"docutils literal notranslate\">id</code> of the model that declares the\n<code class=\"docutils literal notranslate\">ManyToManyField</code>.</p></li>\n<li><p><code class=\"docutils literal notranslate\">&lt;other_model&gt;_id</code>: the <code class=\"docutils literal notranslate\">id</code> of the model that the\n<code class=\"docutils literal notranslate\">ManyToManyField</code> points to.</p></li>\n</ul>\n<p>If the <code class=\"docutils literal notranslate\">ManyToManyField</code> points from and to the same model, the following\nfields are generated:</p>\n<ul class=\"simple\">\n<li><p><code class=\"docutils literal notranslate\">id</code>: the primary key of the relation.</p></li>\n<li><p><code class=\"docutils literal notranslate\">from_&lt;model&gt;_id</code>: the <code class=\"docutils literal notranslate\">id</code> of the instance which points at the\nmodel (i.e. the source instance).</p></li>\n<li><p><code class=\"docutils literal notranslate\">to_&lt;model&gt;_id</code>: the <code class=\"docutils literal notranslate\">id</code> of the instance to which the relationship\npoints (i.e. the target model instance).</p></li>\n</ul>\n<p>This class can be used to query associated records for a given model\ninstance like a normal model.</p>\n</dd></dl>\n\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.ManyToManyField.through_fields\">\n<span class=\"sig-prename descclassname\">ManyToManyField.</span><span class=\"sig-name descname\">through_fields</span><a class=\"heading-anchor\" href=\"#django.db.models.ManyToManyField.through_fields\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Only used when a custom intermediary model is specified. Django will\nnormally determine which fields of the intermediary model to use in order\nto establish a many-to-many relationship automatically. However,\nconsider the following models:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">from</span> <span class=\"nn\">django.db</span> <span class=\"kn\">import</span> models\n\n<span class=\"k\">class</span> <span class=\"nc\">Person</span><span class=\"p\">(</span>models<span class=\"o\">.</span>Model<span class=\"p\">):</span>\n    name <span class=\"o\">=</span> models<span class=\"o\">.</span>CharField<span class=\"p\">(</span>max_length<span class=\"o\">=</span><span class=\"mi\">50</span><span class=\"p\">)</span>\n\n<span class=\"k\">class</span> <span class=\"nc\">Group</span><span class=\"p\">(</span>models<span class=\"o\">.</span>Model<span class=\"p\">):</span>\n    name <span class=\"o\">=</span> models<span class=\"o\">.</span>CharField<span class=\"p\">(</span>max_length<span class=\"o\">=</span><span class=\"mi\">128</span><span class=\"p\">)</span>\n    members <span class=\"o\">=</span> models<span class=\"o\">.</span>ManyToManyField<span class=\"p\">(</span>\n        Person<span class=\"p\">,</span>\n        through<span class=\"o\">=</span><span class=\"s1\">&#39;Membership&#39;</span><span class=\"p\">,</span>\n        through_fields<span class=\"o\">=</span><span class=\"p\">(</span><span class=\"s1\">&#39;group&#39;</span><span class=\"p\">,</span> <span class=\"s1\">&#39;person&#39;</span><span class=\"p\">),</span>\n    <span class=\"p\">)</span>\n\n<span class=\"k\">class</span> <span class=\"nc\">Membership</span><span class=\"p\">(</span>models<span class=\"o\">.</span>Model<span class=\"p\">):</span>\n    group <span class=\"o\">=</span> models<span class=\"o\">.</span>ForeignKey<span class=\"p\">(</span>Group<span class=\"p\">,</span> on_delete<span class=\"o\">=</span>models<span class=\"o\">.</span>CASCADE<span class=\"p\">)</span>\n    person <span class=\"o\">=</span> models<span class=\"o\">.</span>ForeignKey<span class=\"p\">(</span>Person<span class=\"p\">,</span> on_delete<span class=\"o\">=</span>models<span class=\"o\">.</span>CASCADE<span class=\"p\">)</span>\n    inviter <span class=\"o\">=</span> models<span class=\"o\">.</span>ForeignKey<span class=\"p\">(</span>\n        Person<span class=\"p\">,</span>\n        on_delete<span class=\"o\">=</span>models<span class=\"o\">.</span>CASCADE<span class=\"p\">,</span>\n        related_name<span class=\"o\">=</span><span class=\"s2\">&quot;membership_invites&quot;</span><span class=\"p\">,</span>\n    <span class=\"p\">)</span>\n    invite_reason <span class=\"o\">=</span> models<span class=\"o\">.</span>CharField<span class=\"p\">(</span>max_length<span class=\"o\">=</span><span class=\"mi\">64</span><span class=\"p\">)</span>\n</code></pre></div>\n<p><code class=\"docutils literal notranslate\">Membership</code> has <em>two</em> foreign keys to <code class=\"docutils literal notranslate\">Person</code> (<code class=\"docutils literal notranslate\">person</code> and\n<code class=\"docutils literal notranslate\">inviter</code>), which makes the relationship ambiguous and Django can't know\nwhich one to use. In this case, you must explicitly specify which\nforeign keys Django should use using <code class=\"docutils literal notranslate\">through_fields</code>, as in the example\nabove.</p>\n<p><code class=\"docutils literal notranslate\">through_fields</code> accepts a 2-tuple <code class=\"docutils literal notranslate\">('field1', 'field2')</code>, where\n<code class=\"docutils literal notranslate\">field1</code> is the name of the foreign key to the model the\n<a class=\"reference internal\" href=\"#django.db.models.ManyToManyField\" title=\"django.db.models.ManyToManyField\"><code class=\"xref py py-class docutils literal notranslate\">ManyToManyField</code></a> is defined on (<code class=\"docutils literal notranslate\">group</code> in this case), and\n<code class=\"docutils literal notranslate\">field2</code> the name of the foreign key to the target model (<code class=\"docutils literal notranslate\">person</code>\nin this case).</p>\n<p>When you have more than one foreign key on an intermediary model to any\n(or even both) of the models participating in a many-to-many relationship,\nyou <em>must</em> specify <code class=\"docutils literal notranslate\">through_fields</code>. This also applies to\n<a class=\"reference internal\" href=\"#recursive-relationships\"><span class=\"std std-ref\">recursive relationships</span></a>\nwhen an intermediary model is used and there are more than two\nforeign keys to the model, or you want to explicitly specify which two\nDjango should use.</p>\n<p>Recursive relationships using an intermediary model are always defined as\nnon-symmetrical -- that is, with <a class=\"reference internal\" href=\"#django.db.models.ManyToManyField.symmetrical\" title=\"django.db.models.ManyToManyField.symmetrical\"><code class=\"xref py py-attr docutils literal notranslate\">symmetrical=False</code></a>\n-- therefore, there is the concept of a &quot;source&quot; and a &quot;target&quot;. In that\ncase <code class=\"docutils literal notranslate\">'field1'</code> will be treated as the &quot;source&quot; of the relationship and\n<code class=\"docutils literal notranslate\">'field2'</code> as the &quot;target&quot;.</p>\n</dd></dl>\n\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.ManyToManyField.db_table\">\n<span class=\"sig-prename descclassname\">ManyToManyField.</span><span class=\"sig-name descname\">db_table</span><a class=\"heading-anchor\" href=\"#django.db.models.ManyToManyField.db_table\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>The name of the table to create for storing the many-to-many data. If this\nis not provided, Django will assume a default name based upon the names of:\nthe table for the model defining the relationship and the name of the field\nitself.</p>\n</dd></dl>\n\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.ManyToManyField.db_constraint\">\n<span class=\"sig-prename descclassname\">ManyToManyField.</span><span class=\"sig-name descname\">db_constraint</span><a class=\"heading-anchor\" href=\"#django.db.models.ManyToManyField.db_constraint\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Controls whether or not constraints should be created in the database for\nthe foreign keys in the intermediary table. The default is <code class=\"docutils literal notranslate\">True</code>, and\nthat's almost certainly what you want; setting this to <code class=\"docutils literal notranslate\">False</code> can be\nvery bad for data integrity. That said, here are some scenarios where you\nmight want to do this:</p>\n<ul class=\"simple\">\n<li><p>You have legacy data that is not valid.</p></li>\n<li><p>You're sharding your database.</p></li>\n</ul>\n<p>It is an error to pass both <code class=\"docutils literal notranslate\">db_constraint</code> and <code class=\"docutils literal notranslate\">through</code>.</p>\n</dd></dl>\n\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.ManyToManyField.swappable\">\n<span class=\"sig-prename descclassname\">ManyToManyField.</span><span class=\"sig-name descname\">swappable</span><a class=\"heading-anchor\" href=\"#django.db.models.ManyToManyField.swappable\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Controls the migration framework's reaction if this <a class=\"reference internal\" href=\"#django.db.models.ManyToManyField\" title=\"django.db.models.ManyToManyField\"><code class=\"xref py py-class docutils literal notranslate\">ManyToManyField</code></a>\nis pointing at a swappable model. If it is <code class=\"docutils literal notranslate\">True</code> - the default -\nthen if the <a class=\"reference internal\" href=\"#django.db.models.ManyToManyField\" title=\"django.db.models.ManyToManyField\"><code class=\"xref py py-class docutils literal notranslate\">ManyToManyField</code></a> is pointing at a model which matches\nthe current value of <code class=\"docutils literal notranslate\">settings.AUTH_USER_MODEL</code> (or another swappable\nmodel setting) the relationship will be stored in the migration using\na reference to the setting, not to the model directly.</p>\n<p>You only want to override this to be <code class=\"docutils literal notranslate\">False</code> if you are sure your\nmodel should always point towards the swapped-in model - for example,\nif it is a profile model designed specifically for your custom user model.</p>\n<p>If in doubt, leave it to its default of <code class=\"docutils literal notranslate\">True</code>.</p>\n</dd></dl>\n\n<p><a class=\"reference internal\" href=\"#django.db.models.ManyToManyField\" title=\"django.db.models.ManyToManyField\"><code class=\"xref py py-class docutils literal notranslate\">ManyToManyField</code></a> does not support <a class=\"reference internal\" href=\"#django.db.models.Field.validators\" title=\"django.db.models.Field.validators\"><code class=\"xref py py-attr docutils literal notranslate\">validators</code></a>.</p>\n<p><a class=\"reference internal\" href=\"#django.db.models.Field.null\" title=\"django.db.models.Field.null\"><code class=\"xref py py-attr docutils literal notranslate\">null</code></a> has no effect since there is no way to require a\nrelationship at the database level.</p>\n</section>\n</section>\n<section id=\"onetoonefield\">\n<h3><code class=\"docutils literal notranslate\">OneToOneField</code><a class=\"heading-anchor\" href=\"#onetoonefield\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.OneToOneField\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">OneToOneField</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">othermodel</em>, <em class=\"sig-param\">on_delete</em>, <em class=\"sig-param\">parent_link<span class=\"o\">=</span><span class=\"default_value\">False</span></em>, <em class=\"sig-param\"><span class=\"o\">**</span>options</em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.db.models.OneToOneField\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>A one-to-one relationship. Conceptually, this is similar to a\n<a class=\"reference internal\" href=\"#django.db.models.ForeignKey\" title=\"django.db.models.ForeignKey\"><code class=\"xref py py-class docutils literal notranslate\">ForeignKey</code></a> with <a class=\"reference internal\" href=\"#django.db.models.Field.unique\" title=\"django.db.models.Field.unique\"><code class=\"xref py py-attr docutils literal notranslate\">unique=True</code></a>, but the\n&quot;reverse&quot; side of the relation will directly return a single object.</p>\n<aside class=\"version-note version-changed\" data-version=\"1.9\" role=\"note\">\n<p class=\"version-note-title\">Changed in Django 1.9</p><p><code class=\"docutils literal notranslate\">on_delete</code> が 2 番目の引数として使用できるようになりました。(以前は、通常はキーワード引数としてのみ渡されていました)。Django 2.0 では必須の引数になる予定です。</p>\n</aside>\n<p>This is most useful as the primary key of a model which &quot;extends&quot;\nanother model in some way; <a class=\"reference internal\" href=\"/ja/1.10/topics/db/models/#multi-table-inheritance\"><span class=\"std std-ref\">複数テーブルの継承</span></a> is\nimplemented by adding an implicit one-to-one relation from the child\nmodel to the parent model, for example.</p>\n<p>One positional argument is required: the class to which the model will be\nrelated. This works exactly the same as it does for <a class=\"reference internal\" href=\"#django.db.models.ForeignKey\" title=\"django.db.models.ForeignKey\"><code class=\"xref py py-class docutils literal notranslate\">ForeignKey</code></a>,\nincluding all the options regarding <a class=\"reference internal\" href=\"#recursive-relationships\"><span class=\"std std-ref\">recursive</span></a>\nand <a class=\"reference internal\" href=\"#lazy-relationships\"><span class=\"std std-ref\">lazy</span></a> relationships.</p>\n<p>If you do not specify the <a class=\"reference internal\" href=\"#django.db.models.ForeignKey.related_name\" title=\"django.db.models.ForeignKey.related_name\"><code class=\"xref py py-attr docutils literal notranslate\">related_name</code></a> argument for\nthe <code class=\"docutils literal notranslate\">OneToOneField</code>, Django will use the lower-case name of the current model\nas default value.</p>\n<p>With the following example:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">from</span> <span class=\"nn\">django.conf</span> <span class=\"kn\">import</span> settings\n<span class=\"kn\">from</span> <span class=\"nn\">django.db</span> <span class=\"kn\">import</span> models\n\n<span class=\"k\">class</span> <span class=\"nc\">MySpecialUser</span><span class=\"p\">(</span>models<span class=\"o\">.</span>Model<span class=\"p\">):</span>\n    user <span class=\"o\">=</span> models<span class=\"o\">.</span>OneToOneField<span class=\"p\">(</span>\n        settings<span class=\"o\">.</span>AUTH_USER_MODEL<span class=\"p\">,</span>\n        on_delete<span class=\"o\">=</span>models<span class=\"o\">.</span>CASCADE<span class=\"p\">,</span>\n    <span class=\"p\">)</span>\n    supervisor <span class=\"o\">=</span> models<span class=\"o\">.</span>OneToOneField<span class=\"p\">(</span>\n        settings<span class=\"o\">.</span>AUTH_USER_MODEL<span class=\"p\">,</span>\n        on_delete<span class=\"o\">=</span>models<span class=\"o\">.</span>CASCADE<span class=\"p\">,</span>\n        related_name<span class=\"o\">=</span><span class=\"s1\">&#39;supervisor_of&#39;</span><span class=\"p\">,</span>\n    <span class=\"p\">)</span>\n</code></pre></div>\n<p>your resulting <code class=\"docutils literal notranslate\">User</code> model will have the following attributes:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"gp\">&gt;&gt;&gt; </span>user <span class=\"o\">=</span> User<span class=\"o\">.</span>objects<span class=\"o\">.</span>get<span class=\"p\">(</span>pk<span class=\"o\">=</span><span class=\"mi\">1</span><span class=\"p\">)</span>\n<span class=\"gp\">&gt;&gt;&gt; </span><span class=\"nb\">hasattr</span><span class=\"p\">(</span>user<span class=\"p\">,</span> <span class=\"s1\">&#39;myspecialuser&#39;</span><span class=\"p\">)</span>\n<span class=\"go\">True</span>\n<span class=\"gp\">&gt;&gt;&gt; </span><span class=\"nb\">hasattr</span><span class=\"p\">(</span>user<span class=\"p\">,</span> <span class=\"s1\">&#39;supervisor_of&#39;</span><span class=\"p\">)</span>\n<span class=\"go\">True</span>\n</code></pre></div>\n<p>A <code class=\"docutils literal notranslate\">DoesNotExist</code> exception is raised when accessing the reverse relationship\nif an entry in the related table doesn't exist. For example, if a user doesn't\nhave a supervisor designated by <code class=\"docutils literal notranslate\">MySpecialUser</code>:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"gp\">&gt;&gt;&gt; </span>user<span class=\"o\">.</span>supervisor_of\n<span class=\"gt\">Traceback (most recent call last):</span>\n    <span class=\"o\">...</span>\n<span class=\"gr\">DoesNotExist</span>: User matching query does not exist.\n</code></pre></div>\n<p id=\"onetoone-arguments\">Additionally, <code class=\"docutils literal notranslate\">OneToOneField</code> accepts all of the extra arguments\naccepted by <a class=\"reference internal\" href=\"#django.db.models.ForeignKey\" title=\"django.db.models.ForeignKey\"><code class=\"xref py py-class docutils literal notranslate\">ForeignKey</code></a>, plus one extra argument:</p>\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.OneToOneField.parent_link\">\n<span class=\"sig-prename descclassname\">OneToOneField.</span><span class=\"sig-name descname\">parent_link</span><a class=\"heading-anchor\" href=\"#django.db.models.OneToOneField.parent_link\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>When <code class=\"docutils literal notranslate\">True</code> and used in a model which inherits from another\n<a class=\"reference internal\" href=\"/ja/1.10/glossary/#term-concrete-model\"><span class=\"xref std std-term\">concrete model</span></a>, indicates that this field should be used as the\nlink back to the parent class, rather than the extra\n<code class=\"docutils literal notranslate\">OneToOneField</code> which would normally be implicitly created by\nsubclassing.</p>\n</dd></dl>\n\n<p>See <a class=\"reference internal\" href=\"/ja/1.10/topics/db/examples/one_to_one/\"><span class=\"doc\">One-to-one relationships</span></a> for usage\nexamples of <code class=\"docutils literal notranslate\">OneToOneField</code>.</p>\n</section>\n</section>\n<section id=\"field-api-reference\">\n<h2>Field API reference<a class=\"heading-anchor\" href=\"#field-api-reference\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.Field\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">Field</span><a class=\"heading-anchor\" href=\"#django.db.models.Field\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p><code class=\"docutils literal notranslate\">Field</code> is an abstract class that represents a database table column.\nDjango uses fields to create the database table (<a class=\"reference internal\" href=\"#django.db.models.Field.db_type\" title=\"django.db.models.Field.db_type\"><code class=\"xref py py-meth docutils literal notranslate\">db_type()</code></a>), to map\nPython types to database (<a class=\"reference internal\" href=\"#django.db.models.Field.get_prep_value\" title=\"django.db.models.Field.get_prep_value\"><code class=\"xref py py-meth docutils literal notranslate\">get_prep_value()</code></a>) and vice-versa\n(<a class=\"reference internal\" href=\"#django.db.models.Field.from_db_value\" title=\"django.db.models.Field.from_db_value\"><code class=\"xref py py-meth docutils literal notranslate\">from_db_value()</code></a>).</p>\n<p>A field is thus a fundamental piece in different Django APIs, notably,\n<a class=\"reference internal\" href=\"/ja/1.10/ref/models/instances/#django.db.models.Model\" title=\"django.db.models.Model\"><code class=\"xref py py-class docutils literal notranslate\">models</code></a> and <a class=\"reference internal\" href=\"/ja/1.10/ref/models/querysets/#django.db.models.query.QuerySet\" title=\"django.db.models.query.QuerySet\"><code class=\"xref py py-class docutils literal notranslate\">querysets</code></a>.</p>\n<p>In models, a field is instantiated as a class attribute and represents a\nparticular table column, see <a class=\"reference internal\" href=\"/ja/1.10/topics/db/models/\"><span class=\"doc\">モデル</span></a>. It has attributes\nsuch as <a class=\"reference internal\" href=\"#django.db.models.Field.null\" title=\"django.db.models.Field.null\"><code class=\"xref py py-attr docutils literal notranslate\">null</code></a> and <a class=\"reference internal\" href=\"#django.db.models.Field.unique\" title=\"django.db.models.Field.unique\"><code class=\"xref py py-attr docutils literal notranslate\">unique</code></a>, and methods that Django uses to\nmap the field value to database-specific values.</p>\n<p>A <code class=\"docutils literal notranslate\">Field</code> is a subclass of\n<a class=\"reference internal\" href=\"/ja/1.10/ref/models/lookups/#django.db.models.lookups.RegisterLookupMixin\" title=\"django.db.models.lookups.RegisterLookupMixin\"><code class=\"xref py py-class docutils literal notranslate\">RegisterLookupMixin</code></a> and thus both\n<a class=\"reference internal\" href=\"/ja/1.10/ref/models/lookups/#django.db.models.Transform\" title=\"django.db.models.Transform\"><code class=\"xref py py-class docutils literal notranslate\">Transform</code></a> and\n<a class=\"reference internal\" href=\"/ja/1.10/ref/models/lookups/#django.db.models.Lookup\" title=\"django.db.models.Lookup\"><code class=\"xref py py-class docutils literal notranslate\">Lookup</code></a> can be registered on it to be used\nin <code class=\"docutils literal notranslate\">QuerySet</code>s (e.g. <code class=\"docutils literal notranslate\">field_name__exact=&quot;foo&quot;</code>). All <a class=\"reference internal\" href=\"/ja/1.10/ref/models/querysets/#field-lookups\"><span class=\"std std-ref\">built-in\nlookups</span></a> are registered by default.</p>\n<p>All of Django's built-in fields, such as <a class=\"reference internal\" href=\"#django.db.models.CharField\" title=\"django.db.models.CharField\"><code class=\"xref py py-class docutils literal notranslate\">CharField</code></a>, are particular\nimplementations of <code class=\"docutils literal notranslate\">Field</code>. If you need a custom field, you can either\nsubclass any of the built-in fields or write a <code class=\"docutils literal notranslate\">Field</code> from scratch. In\neither case, see <a class=\"reference internal\" href=\"/ja/1.10/howto/custom-model-fields/\"><span class=\"doc\">Writing custom model fields</span></a>.</p>\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.Field.description\">\n<span class=\"sig-name descname\">description</span><a class=\"heading-anchor\" href=\"#django.db.models.Field.description\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>A verbose description of the field, e.g. for the\n<a class=\"reference internal\" href=\"/ja/1.10/ref/contrib/admin/admindocs/#module-django.contrib.admindocs\" title=\"django.contrib.admindocs: Django's admin documentation generator.\"><code class=\"xref py py-mod docutils literal notranslate\">django.contrib.admindocs</code></a> application.</p>\n<p>The description can be of the form:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code>description <span class=\"o\">=</span> _<span class=\"p\">(</span><span class=\"s2\">&quot;String (up to </span><span class=\"si\">%(max_length)s</span><span class=\"s2\">)&quot;</span><span class=\"p\">)</span>\n</code></pre></div>\n<p>where the arguments are interpolated from the field's <code class=\"docutils literal notranslate\">__dict__</code>.</p>\n</dd></dl>\n\n<p>To map a <code class=\"docutils literal notranslate\">Field</code> to a database-specific type, Django exposes several\nmethods:</p>\n<dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.Field.get_internal_type\">\n<span class=\"sig-name descname\">get_internal_type</span><span class=\"sig-paren\">(</span><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.db.models.Field.get_internal_type\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Returns a string naming this field for backend specific purposes.\nBy default, it returns the class name.</p>\n<p>See <a class=\"reference internal\" href=\"/ja/1.10/howto/custom-model-fields/#emulating-built-in-field-types\"><span class=\"std std-ref\">Emulating built-in field types</span></a> for usage in custom fields.</p>\n</dd></dl>\n\n<dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.Field.db_type\">\n<span class=\"sig-name descname\">db_type</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">connection</em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.db.models.Field.db_type\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Returns the database column data type for the <a class=\"reference internal\" href=\"#django.db.models.Field\" title=\"django.db.models.Field\"><code class=\"xref py py-class docutils literal notranslate\">Field</code></a>, taking\ninto account the <code class=\"docutils literal notranslate\">connection</code>.</p>\n<p>See <a class=\"reference internal\" href=\"/ja/1.10/howto/custom-model-fields/#custom-database-types\"><span class=\"std std-ref\">Custom database types</span></a> for usage in custom fields.</p>\n</dd></dl>\n\n<dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.Field.rel_db_type\">\n<span class=\"sig-name descname\">rel_db_type</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">connection</em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.db.models.Field.rel_db_type\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><aside class=\"version-note version-added\" data-version=\"1.10\" role=\"note\">\n<p class=\"version-note-title\">New in Django 1.10</p></aside>\n<p>Returns the database column data type for fields such as <code class=\"docutils literal notranslate\">ForeignKey</code>\nand <code class=\"docutils literal notranslate\">OneToOneField</code> that point to the <a class=\"reference internal\" href=\"#django.db.models.Field\" title=\"django.db.models.Field\"><code class=\"xref py py-class docutils literal notranslate\">Field</code></a>, taking\ninto account the <code class=\"docutils literal notranslate\">connection</code>.</p>\n<p>See <a class=\"reference internal\" href=\"/ja/1.10/howto/custom-model-fields/#custom-database-types\"><span class=\"std std-ref\">Custom database types</span></a> for usage in custom fields.</p>\n</dd></dl>\n\n<p>There are three main situations where Django needs to interact with the\ndatabase backend and fields:</p>\n<ul class=\"simple\">\n<li><p>when it queries the database (Python value -&gt; database backend value)</p></li>\n<li><p>when it loads data from the database (database backend value -&gt; Python\nvalue)</p></li>\n<li><p>when it saves to the database (Python value -&gt; database backend value)</p></li>\n</ul>\n<p>When querying, <a class=\"reference internal\" href=\"#django.db.models.Field.get_db_prep_value\" title=\"django.db.models.Field.get_db_prep_value\"><code class=\"xref py py-meth docutils literal notranslate\">get_db_prep_value()</code></a> and <a class=\"reference internal\" href=\"#django.db.models.Field.get_prep_value\" title=\"django.db.models.Field.get_prep_value\"><code class=\"xref py py-meth docutils literal notranslate\">get_prep_value()</code></a> are used:</p>\n<dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.Field.get_prep_value\">\n<span class=\"sig-name descname\">get_prep_value</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">value</em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.db.models.Field.get_prep_value\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p><code class=\"docutils literal notranslate\">value</code> is the current value of the model's attribute, and the method\nshould return data in a format that has been prepared for use as a\nparameter in a query.</p>\n<p>See <a class=\"reference internal\" href=\"/ja/1.10/howto/custom-model-fields/#converting-python-objects-to-query-values\"><span class=\"std std-ref\">Converting Python objects to query values</span></a> for usage.</p>\n</dd></dl>\n\n<dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.Field.get_db_prep_value\">\n<span class=\"sig-name descname\">get_db_prep_value</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">value</em>, <em class=\"sig-param\">connection</em>, <em class=\"sig-param\">prepared<span class=\"o\">=</span><span class=\"default_value\">False</span></em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.db.models.Field.get_db_prep_value\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Converts <code class=\"docutils literal notranslate\">value</code> to a backend-specific value. By default it returns\n<code class=\"docutils literal notranslate\">value</code> if <code class=\"docutils literal notranslate\">prepared=True</code> and <a class=\"reference internal\" href=\"#django.db.models.Field.get_prep_value\" title=\"django.db.models.Field.get_prep_value\"><code class=\"xref py py-meth docutils literal notranslate\">get_prep_value()</code></a> if is\n<code class=\"docutils literal notranslate\">False</code>.</p>\n<p>See <a class=\"reference internal\" href=\"/ja/1.10/howto/custom-model-fields/#converting-query-values-to-database-values\"><span class=\"std std-ref\">Converting query values to database values</span></a> for usage.</p>\n</dd></dl>\n\n<p>When loading data, <a class=\"reference internal\" href=\"#django.db.models.Field.from_db_value\" title=\"django.db.models.Field.from_db_value\"><code class=\"xref py py-meth docutils literal notranslate\">from_db_value()</code></a> is used:</p>\n<dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.Field.from_db_value\">\n<span class=\"sig-name descname\">from_db_value</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">value</em>, <em class=\"sig-param\">expression</em>, <em class=\"sig-param\">connection</em>, <em class=\"sig-param\">context</em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.db.models.Field.from_db_value\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Converts a value as returned by the database to a Python object. It is\nthe reverse of <a class=\"reference internal\" href=\"#django.db.models.Field.get_prep_value\" title=\"django.db.models.Field.get_prep_value\"><code class=\"xref py py-meth docutils literal notranslate\">get_prep_value()</code></a>.</p>\n<p>This method is not used for most built-in fields as the database\nbackend already returns the correct Python type, or the backend itself\ndoes the conversion.</p>\n<p>See <a class=\"reference internal\" href=\"/ja/1.10/howto/custom-model-fields/#converting-values-to-python-objects\"><span class=\"std std-ref\">Converting values to Python objects</span></a> for usage.</p>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">注釈</p>\n<p>For performance reasons, <code class=\"docutils literal notranslate\">from_db_value</code> is not implemented as a\nno-op on fields which do not require it (all Django fields).\nConsequently you may not call <code class=\"docutils literal notranslate\">super</code> in your definition.</p>\n</aside>\n</dd></dl>\n\n<p>When saving, <a class=\"reference internal\" href=\"#django.db.models.Field.pre_save\" title=\"django.db.models.Field.pre_save\"><code class=\"xref py py-meth docutils literal notranslate\">pre_save()</code></a> and <a class=\"reference internal\" href=\"#django.db.models.Field.get_db_prep_save\" title=\"django.db.models.Field.get_db_prep_save\"><code class=\"xref py py-meth docutils literal notranslate\">get_db_prep_save()</code></a> are used:</p>\n<dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.Field.get_db_prep_save\">\n<span class=\"sig-name descname\">get_db_prep_save</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">value</em>, <em class=\"sig-param\">connection</em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.db.models.Field.get_db_prep_save\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Same as the <a class=\"reference internal\" href=\"#django.db.models.Field.get_db_prep_value\" title=\"django.db.models.Field.get_db_prep_value\"><code class=\"xref py py-meth docutils literal notranslate\">get_db_prep_value()</code></a>, but called when the field value\nmust be <em>saved</em> to the database. By default returns\n<a class=\"reference internal\" href=\"#django.db.models.Field.get_db_prep_value\" title=\"django.db.models.Field.get_db_prep_value\"><code class=\"xref py py-meth docutils literal notranslate\">get_db_prep_value()</code></a>.</p>\n</dd></dl>\n\n<dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.Field.pre_save\">\n<span class=\"sig-name descname\">pre_save</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">model_instance</em>, <em class=\"sig-param\">add</em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.db.models.Field.pre_save\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Method called prior to <a class=\"reference internal\" href=\"#django.db.models.Field.get_db_prep_save\" title=\"django.db.models.Field.get_db_prep_save\"><code class=\"xref py py-meth docutils literal notranslate\">get_db_prep_save()</code></a> to prepare the value\nbefore being saved (e.g. for <a class=\"reference internal\" href=\"#django.db.models.DateField.auto_now\" title=\"django.db.models.DateField.auto_now\"><code class=\"xref py py-attr docutils literal notranslate\">DateField.auto_now</code></a>).</p>\n<p><code class=\"docutils literal notranslate\">model_instance</code> is the instance this field belongs to and <code class=\"docutils literal notranslate\">add</code>\nis whether the instance is being saved to the database for the first\ntime.</p>\n<p>It should return the value of the appropriate attribute from\n<code class=\"docutils literal notranslate\">model_instance</code> for this field. The attribute name is in\n<code class=\"docutils literal notranslate\">self.attname</code> (this is set up by <a class=\"reference internal\" href=\"#django.db.models.Field\" title=\"django.db.models.Field\"><code class=\"xref py py-class docutils literal notranslate\">Field</code></a>).</p>\n<p>See <a class=\"reference internal\" href=\"/ja/1.10/howto/custom-model-fields/#preprocessing-values-before-saving\"><span class=\"std std-ref\">Preprocessing values before saving</span></a> for usage.</p>\n</dd></dl>\n\n<p>Fields often receive their values as a different type, either from\nserialization or from forms.</p>\n<dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.Field.to_python\">\n<span class=\"sig-name descname\">to_python</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">value</em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.db.models.Field.to_python\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Converts the value into the correct Python object. It acts as the\nreverse of <a class=\"reference internal\" href=\"#django.db.models.Field.value_to_string\" title=\"django.db.models.Field.value_to_string\"><code class=\"xref py py-meth docutils literal notranslate\">value_to_string()</code></a>, and is also called in\n<a class=\"reference internal\" href=\"/ja/1.10/ref/models/instances/#django.db.models.Model.clean\" title=\"django.db.models.Model.clean\"><code class=\"xref py py-meth docutils literal notranslate\">clean()</code></a>.</p>\n<p>See <a class=\"reference internal\" href=\"/ja/1.10/howto/custom-model-fields/#converting-values-to-python-objects\"><span class=\"std std-ref\">Converting values to Python objects</span></a> for usage.</p>\n</dd></dl>\n\n<p>Besides saving to the database, the field also needs to know how to\nserialize its value:</p>\n<dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.Field.value_to_string\">\n<span class=\"sig-name descname\">value_to_string</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">obj</em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.db.models.Field.value_to_string\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Converts <code class=\"docutils literal notranslate\">obj</code> to a string. Used to serialize the value of the field.</p>\n<p>See <a class=\"reference internal\" href=\"/ja/1.10/howto/custom-model-fields/#converting-model-field-to-serialization\"><span class=\"std std-ref\">Converting field data for serialization</span></a> for usage.</p>\n</dd></dl>\n\n<p>When using <a class=\"reference internal\" href=\"/ja/1.10/topics/forms/modelforms/#django.forms.ModelForm\" title=\"django.forms.ModelForm\"><code class=\"xref py py-class docutils literal notranslate\">model forms</code></a>, the <code class=\"docutils literal notranslate\">Field</code>\nneeds to know which form field it should be represented by:</p>\n<dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.Field.formfield\">\n<span class=\"sig-name descname\">formfield</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">form_class<span class=\"o\">=</span><span class=\"default_value\">None</span></em>, <em class=\"sig-param\">choices_form_class<span class=\"o\">=</span><span class=\"default_value\">None</span></em>, <em class=\"sig-param\"><span class=\"o\">**</span>kwargs</em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.db.models.Field.formfield\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Returns the default <a class=\"reference internal\" href=\"/ja/1.10/ref/forms/fields/#django.forms.Field\" title=\"django.forms.Field\"><code class=\"xref py py-class docutils literal notranslate\">django.forms.Field</code></a> of this field for\n<a class=\"reference internal\" href=\"/ja/1.10/topics/forms/modelforms/#django.forms.ModelForm\" title=\"django.forms.ModelForm\"><code class=\"xref py py-class docutils literal notranslate\">ModelForm</code></a>.</p>\n<p>By default, if both <code class=\"docutils literal notranslate\">form_class</code> and <code class=\"docutils literal notranslate\">choices_form_class</code> are\n<code class=\"docutils literal notranslate\">None</code>, it uses <a class=\"reference internal\" href=\"/ja/1.10/ref/forms/fields/#django.forms.CharField\" title=\"django.forms.CharField\"><code class=\"xref py py-class docutils literal notranslate\">CharField</code></a>. If the field has\n<a class=\"reference internal\" href=\"#django.db.models.Field.choices\" title=\"django.db.models.Field.choices\"><code class=\"xref py py-attr docutils literal notranslate\">choices</code></a> and <code class=\"docutils literal notranslate\">choices_form_class</code>\nisn't specified, it uses <a class=\"reference internal\" href=\"/ja/1.10/ref/forms/fields/#django.forms.TypedChoiceField\" title=\"django.forms.TypedChoiceField\"><code class=\"xref py py-class docutils literal notranslate\">TypedChoiceField</code></a>.</p>\n<p>See <a class=\"reference internal\" href=\"/ja/1.10/howto/custom-model-fields/#specifying-form-field-for-model-field\"><span class=\"std std-ref\">Specifying the form field for a model field</span></a> for usage.</p>\n</dd></dl>\n\n<dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.Field.deconstruct\">\n<span class=\"sig-name descname\">deconstruct</span><span class=\"sig-paren\">(</span><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.db.models.Field.deconstruct\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Returns a 4-tuple with enough information to recreate the field:</p>\n<ol class=\"arabic simple\">\n<li><p>The name of the field on the model.</p></li>\n<li><p>The import path of the field (e.g. <code class=\"docutils literal notranslate\">&quot;django.db.models.IntegerField&quot;</code>).\nThis should be the most portable version, so less specific may be better.</p></li>\n<li><p>A list of positional arguments.</p></li>\n<li><p>A dict of keyword arguments.</p></li>\n</ol>\n<p>This method must be added to fields prior to 1.7 to migrate its data\nusing <a class=\"reference internal\" href=\"/ja/1.10/topics/migrations/\"><span class=\"doc\">マイグレーション</span></a>.</p>\n</dd></dl>\n\n</dd></dl>\n\n</section>\n</section>\n<section id=\"field-attribute-reference\">\n<span id=\"model-field-attributes\"></span><h1>Field attribute reference<a class=\"heading-anchor\" href=\"#field-attribute-reference\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h1>\n<p>Every <code class=\"docutils literal notranslate\">Field</code> instance contains several attributes that allow\nintrospecting its behavior. Use these attributes instead of <code class=\"docutils literal notranslate\">isinstance</code>\nchecks when you need to write code that depends on a field's functionality.\nThese attributes can be used together with the <a class=\"reference internal\" href=\"/ja/1.10/ref/models/meta/#model-meta-field-api\"><span class=\"std std-ref\">Model._meta API</span></a> to narrow down a search for specific field types.\nCustom model fields should implement these flags.</p>\n<section id=\"attributes-for-fields\">\n<h2>Attributes for fields<a class=\"heading-anchor\" href=\"#attributes-for-fields\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.Field.auto_created\">\n<span class=\"sig-prename descclassname\">Field.</span><span class=\"sig-name descname\">auto_created</span><a class=\"heading-anchor\" href=\"#django.db.models.Field.auto_created\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Boolean flag that indicates if the field was automatically created, such\nas the <code class=\"docutils literal notranslate\">OneToOneField</code> used by model inheritance.</p>\n</dd></dl>\n\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.Field.concrete\">\n<span class=\"sig-prename descclassname\">Field.</span><span class=\"sig-name descname\">concrete</span><a class=\"heading-anchor\" href=\"#django.db.models.Field.concrete\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Boolean flag that indicates if the field has a database column associated\nwith it.</p>\n</dd></dl>\n\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.Field.hidden\">\n<span class=\"sig-prename descclassname\">Field.</span><span class=\"sig-name descname\">hidden</span><a class=\"heading-anchor\" href=\"#django.db.models.Field.hidden\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Boolean flag that indicates if a field is used to back another non-hidden\nfield's functionality (e.g. the <code class=\"docutils literal notranslate\">content_type</code> and <code class=\"docutils literal notranslate\">object_id</code> fields\nthat make up a <code class=\"docutils literal notranslate\">GenericForeignKey</code>). The <code class=\"docutils literal notranslate\">hidden</code> flag is used to\ndistinguish what constitutes the public subset of fields on the model from\nall the fields on the model.</p>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">注釈</p>\n<p><a class=\"reference internal\" href=\"/ja/1.10/ref/models/meta/#django.db.models.options.Options.get_fields\" title=\"django.db.models.options.Options.get_fields\"><code class=\"xref py py-meth docutils literal notranslate\">Options.get_fields()</code></a>\nexcludes hidden fields by default. Pass in <code class=\"docutils literal notranslate\">include_hidden=True</code> to\nreturn hidden fields in the results.</p>\n</aside>\n</dd></dl>\n\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.Field.is_relation\">\n<span class=\"sig-prename descclassname\">Field.</span><span class=\"sig-name descname\">is_relation</span><a class=\"heading-anchor\" href=\"#django.db.models.Field.is_relation\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Boolean flag that indicates if a field contains references to one or\nmore other models for its functionality (e.g. <code class=\"docutils literal notranslate\">ForeignKey</code>,\n<code class=\"docutils literal notranslate\">ManyToManyField</code>, <code class=\"docutils literal notranslate\">OneToOneField</code>, etc.).</p>\n</dd></dl>\n\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.Field.model\">\n<span class=\"sig-prename descclassname\">Field.</span><span class=\"sig-name descname\">model</span><a class=\"heading-anchor\" href=\"#django.db.models.Field.model\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Returns the model on which the field is defined. If a field is defined on\na superclass of a model, <code class=\"docutils literal notranslate\">model</code> will refer to the superclass, not the\nclass of the instance.</p>\n</dd></dl>\n\n</section>\n<section id=\"attributes-for-fields-with-relations\">\n<h2>Attributes for fields with relations<a class=\"heading-anchor\" href=\"#attributes-for-fields-with-relations\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>These attributes are used to query for the cardinality and other details of a\nrelation. These attribute are present on all fields; however, they will only\nhave boolean values (rather than <code class=\"docutils literal notranslate\">None</code>) if the field is a relation type\n(<a class=\"reference internal\" href=\"#django.db.models.Field.is_relation\" title=\"django.db.models.Field.is_relation\"><code class=\"xref py py-attr docutils literal notranslate\">Field.is_relation=True</code></a>).</p>\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.Field.many_to_many\">\n<span class=\"sig-prename descclassname\">Field.</span><span class=\"sig-name descname\">many_to_many</span><a class=\"heading-anchor\" href=\"#django.db.models.Field.many_to_many\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Boolean flag that is <code class=\"docutils literal notranslate\">True</code> if the field has a many-to-many relation;\n<code class=\"docutils literal notranslate\">False</code> otherwise. The only field included with Django where this is\n<code class=\"docutils literal notranslate\">True</code> is <code class=\"docutils literal notranslate\">ManyToManyField</code>.</p>\n</dd></dl>\n\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.Field.many_to_one\">\n<span class=\"sig-prename descclassname\">Field.</span><span class=\"sig-name descname\">many_to_one</span><a class=\"heading-anchor\" href=\"#django.db.models.Field.many_to_one\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Boolean flag that is <code class=\"docutils literal notranslate\">True</code> if the field has a many-to-one relation, such\nas a <code class=\"docutils literal notranslate\">ForeignKey</code>; <code class=\"docutils literal notranslate\">False</code> otherwise.</p>\n</dd></dl>\n\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.Field.one_to_many\">\n<span class=\"sig-prename descclassname\">Field.</span><span class=\"sig-name descname\">one_to_many</span><a class=\"heading-anchor\" href=\"#django.db.models.Field.one_to_many\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Boolean flag that is <code class=\"docutils literal notranslate\">True</code> if the field has a one-to-many relation, such\nas a <code class=\"docutils literal notranslate\">GenericRelation</code> or the reverse of a <code class=\"docutils literal notranslate\">ForeignKey</code>; <code class=\"docutils literal notranslate\">False</code>\notherwise.</p>\n</dd></dl>\n\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.Field.one_to_one\">\n<span class=\"sig-prename descclassname\">Field.</span><span class=\"sig-name descname\">one_to_one</span><a class=\"heading-anchor\" href=\"#django.db.models.Field.one_to_one\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Boolean flag that is <code class=\"docutils literal notranslate\">True</code> if the field has a one-to-one relation, such\nas a <code class=\"docutils literal notranslate\">OneToOneField</code>; <code class=\"docutils literal notranslate\">False</code> otherwise.</p>\n</dd></dl>\n\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.Field.related_model\">\n<span class=\"sig-prename descclassname\">Field.</span><span class=\"sig-name descname\">related_model</span><a class=\"heading-anchor\" href=\"#django.db.models.Field.related_model\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Points to the model the field relates to. For example, <code class=\"docutils literal notranslate\">Author</code> in\n<code class=\"docutils literal notranslate\">ForeignKey(Author, on_delete=models.CASCADE)</code>. The <code class=\"docutils literal notranslate\">related_model</code> for\na <code class=\"docutils literal notranslate\">GenericForeignKey</code> is always <code class=\"docutils literal notranslate\">None</code>.</p>\n</dd></dl>\n\n</section>\n</section>\n","rootId":"","toc":[{"title":"モデルフィールドリファレンス","anchor":"","children":[{"title":"フィールドオプション","anchor":"field-options","children":[{"title":"null","anchor":"null","children":[]},{"title":"blank","anchor":"blank","children":[]},{"title":"choices","anchor":"choices","children":[]},{"title":"db_column","anchor":"db-column","children":[]},{"title":"db_index","anchor":"db-index","children":[]},{"title":"db_tablespace","anchor":"db-tablespace","children":[]},{"title":"default","anchor":"default","children":[]},{"title":"editable","anchor":"editable","children":[]},{"title":"error_messages","anchor":"error-messages","children":[]},{"title":"help_text","anchor":"help-text","children":[]},{"title":"primary_key","anchor":"primary-key","children":[]},{"title":"unique","anchor":"unique","children":[]},{"title":"unique_for_date","anchor":"unique-for-date","children":[]},{"title":"unique_for_month","anchor":"unique-for-month","children":[]},{"title":"unique_for_year","anchor":"unique-for-year","children":[]},{"title":"verbose_name","anchor":"verbose-name","children":[]},{"title":"validators","anchor":"validators","children":[{"title":"Registering and fetching lookups","anchor":"registering-and-fetching-lookups","children":[]}]}]},{"title":"フィールドの型","anchor":"field-types","children":[{"title":"AutoField","anchor":"autofield","children":[]},{"title":"BigAutoField","anchor":"bigautofield","children":[]},{"title":"BigIntegerField","anchor":"bigintegerfield","children":[]},{"title":"BinaryField","anchor":"binaryfield","children":[]},{"title":"BooleanField","anchor":"booleanfield","children":[]},{"title":"CharField","anchor":"charfield","children":[]},{"title":"CommaSeparatedIntegerField","anchor":"commaseparatedintegerfield","children":[]},{"title":"DateField","anchor":"datefield","children":[]},{"title":"DateTimeField","anchor":"datetimefield","children":[]},{"title":"DecimalField","anchor":"decimalfield","children":[]},{"title":"DurationField","anchor":"durationfield","children":[]},{"title":"EmailField","anchor":"emailfield","children":[]},{"title":"FileField","anchor":"filefield","children":[{"title":"FileField と FieldFile","anchor":"filefield-and-fieldfile","children":[]}]},{"title":"FilePathField","anchor":"filepathfield","children":[]},{"title":"FloatField","anchor":"floatfield","children":[]},{"title":"ImageField","anchor":"imagefield","children":[]},{"title":"IntegerField","anchor":"integerfield","children":[]},{"title":"GenericIPAddressField","anchor":"genericipaddressfield","children":[]},{"title":"NullBooleanField","anchor":"nullbooleanfield","children":[]},{"title":"PositiveIntegerField","anchor":"positiveintegerfield","children":[]},{"title":"PositiveSmallIntegerField","anchor":"positivesmallintegerfield","children":[]},{"title":"SlugField","anchor":"slugfield","children":[]},{"title":"SmallIntegerField","anchor":"smallintegerfield","children":[]},{"title":"TextField","anchor":"textfield","children":[]},{"title":"TimeField","anchor":"timefield","children":[]},{"title":"URLField","anchor":"urlfield","children":[]},{"title":"UUIDField","anchor":"uuidfield","children":[]}]},{"title":"リレーションシップフィールド","anchor":"module-django.db.models.fields.related","children":[{"title":"ForeignKey","anchor":"foreignkey","children":[{"title":"Database Representation","anchor":"database-representation","children":[]},{"title":"引数","anchor":"arguments","children":[]}]},{"title":"ManyToManyField","anchor":"manytomanyfield","children":[{"title":"Database Representation","anchor":"id1","children":[]},{"title":"引数","anchor":"manytomany-arguments","children":[]}]},{"title":"OneToOneField","anchor":"onetoonefield","children":[]}]},{"title":"Field API reference","anchor":"field-api-reference","children":[]}]},{"title":"Field attribute reference","anchor":"field-attribute-reference","children":[{"title":"Attributes for fields","anchor":"attributes-for-fields","children":[]},{"title":"Attributes for fields with relations","anchor":"attributes-for-fields-with-relations","children":[]}]}],"breadcrumbs":[{"docname":"ref/index","title":"API Reference","url":"/ja/1.10/ref/"},{"docname":"ref/models/index","title":"モデル","url":"/ja/1.10/ref/models/"}],"prev":{"docname":"ref/models/index","title":"モデル","url":"/ja/1.10/ref/models/"},"next":{"docname":"ref/models/meta","title":"Model _meta API","url":"/ja/1.10/ref/models/meta/"},"formats":{"html":"/ja/1.10/ref/models/fields/","markdown":"/ja/1.10/ref/models/fields.md","json":"/ja/1.10/ref/models/fields.json"},"source":"https://github.com/django/django/blob/stable/1.10.x/docs/ref/models/fields.txt","official":"https://docs.djangoproject.com/ja/1.10/ref/models/fields/","inVersions":["6.1","6.0","5.2","5.1","5.0","4.2","4.1","4.0","3.2","3.1","3.0","2.2","2.1","2.0","1.11","1.10","1.9"],"inLocales":["en","fr","ja","id","pt-br","es","el","pl"]}