{"title":"Acuan bidang model","version":"6.0","locale":"id","docname":"ref/models/fields","url":"/id/6.0/ref/models/fields/","canonical":"https://djangodocs.dev/id/6.0/ref/models/fields/","summary":"Dokumen ini mengandung semua acuan API dari Field termasuk field options dan field types Django tawarkan.","html":"<section id=\"module-django.db.models.fields\">\n<span id=\"model-field-reference\"></span><h1>Acuan bidang model<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>Dokumen ini mengandung semua acuan API dari <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> termasuk <a class=\"reference internal\" href=\"#field-options\">field options</a> dan <a class=\"reference internal\" href=\"#field-types\">field types</a> Django tawarkan.</p>\n<aside class=\"admonition admonition-seealso\" role=\"note\">\n<p class=\"admonition-title\">Lihat juga</p>\n<p>If the built-in fields don't do the trick, you can try\n<a class=\"extlink-pypi reference external\" href=\"https://pypi.org/project/django-localflavor/\">django-localflavor</a> (<a class=\"reference external\" href=\"https://django-localflavor.readthedocs.io/\">documentation</a>), which contains assorted\npieces of code that are useful for particular countries and cultures.</p>\n<p>Juga, anda dapat dengan mudah <a class=\"reference internal\" href=\"/id/6.0/howto/custom-model-fields/\"><span class=\"doc\">write your own custom model fields</span></a>.</p>\n</aside>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">Catatan</p>\n<p>Fields are defined in <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>, but for convenience\nthey're imported into <a class=\"reference internal\" href=\"/id/6.0/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>. The standard convention is\nto use <code class=\"docutils literal notranslate\">from django.db import models</code> and refer to fields as\n<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>Pilihan bidang<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>Argumen berikut tersedia pada semua jenis bidang. Semua adalah pilihan.</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>Jika <code class=\"docutils literal notranslate\">True</code>, Django akan menyimpan nilai-nilai kosong sebagai <code class=\"docutils literal notranslate\">NULL</code> di basisdata. Awalan adalah <code class=\"docutils literal notranslate\">False</code>.</p>\n<p>Avoid using <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> on string-based fields such as\n<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> and <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>. The Django convention is to use an\nempty string, not <code class=\"docutils literal notranslate\">NULL</code>, as the &quot;no data&quot; state for string-based fields. If\na string-based field has <code class=\"docutils literal notranslate\">null=False</code>, empty strings can still be saved for\n&quot;no data&quot;. If a string-based field has <code class=\"docutils literal notranslate\">null=True</code>, that means it has two\npossible values for &quot;no data&quot;: <code class=\"docutils literal notranslate\">NULL</code>, and the empty string. In most cases,\nit's redundant to have two possible values for &quot;no data&quot;. One exception is when\na <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> has both <code class=\"docutils literal notranslate\">unique=True</code> and <code class=\"docutils literal notranslate\">blank=True</code> set. In this\nsituation, <code class=\"docutils literal notranslate\">null=True</code> is required to avoid unique constraint violations when\nsaving multiple objects with blank values.</p>\n<p>Untuk kedua bidang berdasarkan-string dan bukan-berdasarkan-string, anda juga akan butuh mensetel <code class=\"docutils literal notranslate\">blank=True</code> jika anda berharap mengizinkan nilai kosong dalam formulir, sebagai parameter <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> hanya mempengaruhi penyimpanan basisdata (lihat <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\">Catatan</p>\n<p>Ketika menggunakan backend basisdata Oracle, nilai <code class=\"docutils literal notranslate\">NULL</code> akan disimpan untuk menyatakan string kosong meskipun dari atribut ini.</p>\n</aside>\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>Jika <code class=\"docutils literal notranslate\">True</code>, bidang diizinkan menjadi kosong. Awalan adalah <code class=\"docutils literal notranslate\">False</code>.</p>\n<p>Catat bahwa ini berbeda dari <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> murni hubungan-basisdata, dimana <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> adalah hubungan-pengesahan. Jika sebuah bidang mempunyai <code class=\"docutils literal notranslate\">blank=True</code>, pengesahan formulir akan mengizinkan masukan dari sebuah nilai kosong. Jika sebuah bidang mempunyai <code class=\"docutils literal notranslate\">blank=False</code>, bidang akan diwajibkan.</p>\n<aside class=\"admonition-supplying-missing-values admonition\" role=\"note\">\n<p class=\"admonition-title\">Supplying missing values</p>\n<p><code class=\"docutils literal notranslate\">blank=True</code> can be used with fields having <code class=\"docutils literal notranslate\">null=False</code>, but this will\nrequire implementing <a class=\"reference internal\" href=\"/id/6.0/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> on the model in\norder to programmatically supply any missing values.</p>\n</aside>\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>A mapping or iterable in the format described below to use as choices for this\nfield. If choices are given, they're enforced by\n<a class=\"reference internal\" href=\"/id/6.0/ref/models/instances/#validating-objects\"><span class=\"std std-ref\">model validation</span></a> and the default form widget will\nbe a select box with these choices instead of the standard text field.</p>\n<p>If a mapping is given, the key element is the actual value to be set on the\nmodel, and the second element is the human readable name. 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>YEAR_IN_SCHOOL_CHOICES <span class=\"o\">=</span> <span class=\"p\">{</span>\n    <span class=\"s2\">&quot;FR&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;Freshman&quot;</span><span class=\"p\">,</span>\n    <span class=\"s2\">&quot;SO&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;Sophomore&quot;</span><span class=\"p\">,</span>\n    <span class=\"s2\">&quot;JR&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;Junior&quot;</span><span class=\"p\">,</span>\n    <span class=\"s2\">&quot;SR&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;Senior&quot;</span><span class=\"p\">,</span>\n    <span class=\"s2\">&quot;GR&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;Graduate&quot;</span><span class=\"p\">,</span>\n<span class=\"p\">}</span>\n</code></pre></div>\n<p>You can also pass a <a class=\"reference external\" href=\"https://docs.python.org/3/glossary.html#term-sequence\" title=\"(di Python v3.14)\"><span class=\"xref std std-term\">sequence</span></a> consisting itself of iterables of exactly\ntwo items (e.g. <code class=\"docutils literal notranslate\">[(A1, B1), (A2, B2), …]</code>). The first element in each tuple\nis the actual value to be set on the model, and the second element is the\nhuman-readable name. 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>YEAR_IN_SCHOOL_CHOICES <span class=\"o\">=</span> <span class=\"p\">[</span>\n    <span class=\"p\">(</span><span class=\"s2\">&quot;FR&quot;</span><span class=\"p\">,</span> <span class=\"s2\">&quot;Freshman&quot;</span><span class=\"p\">),</span>\n    <span class=\"p\">(</span><span class=\"s2\">&quot;SO&quot;</span><span class=\"p\">,</span> <span class=\"s2\">&quot;Sophomore&quot;</span><span class=\"p\">),</span>\n    <span class=\"p\">(</span><span class=\"s2\">&quot;JR&quot;</span><span class=\"p\">,</span> <span class=\"s2\">&quot;Junior&quot;</span><span class=\"p\">),</span>\n    <span class=\"p\">(</span><span class=\"s2\">&quot;SR&quot;</span><span class=\"p\">,</span> <span class=\"s2\">&quot;Senior&quot;</span><span class=\"p\">),</span>\n    <span class=\"p\">(</span><span class=\"s2\">&quot;GR&quot;</span><span class=\"p\">,</span> <span class=\"s2\">&quot;Graduate&quot;</span><span class=\"p\">),</span>\n<span class=\"p\">]</span>\n</code></pre></div>\n<p><code class=\"docutils literal notranslate\">choices</code> can also be defined as a callable that expects no arguments and\nreturns any of the formats described above. 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\">get_currencies</span><span class=\"p\">():</span>\n    <span class=\"k\">return</span> <span class=\"p\">{</span>i<span class=\"p\">:</span> i <span class=\"k\">for</span> i <span class=\"ow\">in</span> settings<span class=\"o\">.</span>CURRENCIES<span class=\"p\">}</span>\n\n\n<span class=\"k\">class</span> <span class=\"nc\">Expense</span><span class=\"p\">(</span>models<span class=\"o\">.</span>Model<span class=\"p\">):</span>\n    amount <span class=\"o\">=</span> models<span class=\"o\">.</span>DecimalField<span class=\"p\">(</span>max_digits<span class=\"o\">=</span><span class=\"mi\">10</span><span class=\"p\">,</span> decimal_places<span class=\"o\">=</span><span class=\"mi\">2</span><span class=\"p\">)</span>\n    currency <span class=\"o\">=</span> models<span class=\"o\">.</span>CharField<span class=\"p\">(</span>max_length<span class=\"o\">=</span><span class=\"mi\">3</span><span class=\"p\">,</span> choices<span class=\"o\">=</span>get_currencies<span class=\"p\">)</span>\n</code></pre></div>\n<p>Passing a callable for <code class=\"docutils literal notranslate\">choices</code> can be particularly handy when, for example,\nthe choices are:</p>\n<ul class=\"simple\">\n<li><p>the result of I/O-bound operations (which could potentially be cached), such\nas querying a table in the same or an external database, or accessing the\nchoices from a static file.</p></li>\n<li><p>a list that is mostly stable but could vary from time to time or from\nproject to project. Examples in this category are using third-party apps that\nprovide a well-known inventory of values, such as currencies, countries,\nlanguages, time zones, etc.</p></li>\n</ul>\n<p>Umumnya, itu adalah terbaik menentukan pilihan didalam kelas model, dan menentukan ketetapan bernama-cocok untuk setiap nilai:</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\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=\"s2\">&quot;FR&quot;</span>\n    SOPHOMORE <span class=\"o\">=</span> <span class=\"s2\">&quot;SO&quot;</span>\n    JUNIOR <span class=\"o\">=</span> <span class=\"s2\">&quot;JR&quot;</span>\n    SENIOR <span class=\"o\">=</span> <span class=\"s2\">&quot;SR&quot;</span>\n    GRADUATE <span class=\"o\">=</span> <span class=\"s2\">&quot;GR&quot;</span>\n    YEAR_IN_SCHOOL_CHOICES <span class=\"o\">=</span> <span class=\"p\">{</span>\n        FRESHMAN<span class=\"p\">:</span> <span class=\"s2\">&quot;Freshman&quot;</span><span class=\"p\">,</span>\n        SOPHOMORE<span class=\"p\">:</span> <span class=\"s2\">&quot;Sophomore&quot;</span><span class=\"p\">,</span>\n        JUNIOR<span class=\"p\">:</span> <span class=\"s2\">&quot;Junior&quot;</span><span class=\"p\">,</span>\n        SENIOR<span class=\"p\">:</span> <span class=\"s2\">&quot;Senior&quot;</span><span class=\"p\">,</span>\n        GRADUATE<span class=\"p\">:</span> <span class=\"s2\">&quot;Graduate&quot;</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>Though you can define a choices list outside of a model class and then\nrefer to it, defining the choices and names for each choice inside the\nmodel class keeps all of that information with the class that uses it,\nand helps reference the choices (e.g, <code class=\"docutils literal notranslate\">Student.SOPHOMORE</code>\nwill work anywhere that the <code class=\"docutils literal notranslate\">Student</code> model has been imported).</p>\n<p id=\"field-choices-named-groups\">Anda dapat juga mengumpulkan pilihan tersedia anda kedalam kelompok bernama yang dapat digunakan untuk tujuan organisasi:</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=\"s2\">&quot;Audio&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n        <span class=\"s2\">&quot;vinyl&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;Vinyl&quot;</span><span class=\"p\">,</span>\n        <span class=\"s2\">&quot;cd&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;CD&quot;</span><span class=\"p\">,</span>\n    <span class=\"p\">},</span>\n    <span class=\"s2\">&quot;Video&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n        <span class=\"s2\">&quot;vhs&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;VHS Tape&quot;</span><span class=\"p\">,</span>\n        <span class=\"s2\">&quot;dvd&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;DVD&quot;</span><span class=\"p\">,</span>\n    <span class=\"p\">},</span>\n    <span class=\"s2\">&quot;unknown&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;Unknown&quot;</span><span class=\"p\">,</span>\n<span class=\"p\">}</span>\n</code></pre></div>\n<p>The key of the mapping is the name to apply to the group and the value is the\nchoices inside that group, consisting of the field value and a human-readable\nname for an option. Grouped options may be combined with ungrouped options\nwithin a single mapping (such as the <code class=\"docutils literal notranslate\">&quot;unknown&quot;</code> option in this example).</p>\n<p>You can also use a sequence, e.g. a list of 2-tuples:</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>\n        <span class=\"s2\">&quot;Audio&quot;</span><span class=\"p\">,</span>\n        <span class=\"p\">(</span>\n            <span class=\"p\">(</span><span class=\"s2\">&quot;vinyl&quot;</span><span class=\"p\">,</span> <span class=\"s2\">&quot;Vinyl&quot;</span><span class=\"p\">),</span>\n            <span class=\"p\">(</span><span class=\"s2\">&quot;cd&quot;</span><span class=\"p\">,</span> <span class=\"s2\">&quot;CD&quot;</span><span class=\"p\">),</span>\n        <span class=\"p\">),</span>\n    <span class=\"p\">),</span>\n    <span class=\"p\">(</span>\n        <span class=\"s2\">&quot;Video&quot;</span><span class=\"p\">,</span>\n        <span class=\"p\">(</span>\n            <span class=\"p\">(</span><span class=\"s2\">&quot;vhs&quot;</span><span class=\"p\">,</span> <span class=\"s2\">&quot;VHS Tape&quot;</span><span class=\"p\">),</span>\n            <span class=\"p\">(</span><span class=\"s2\">&quot;dvd&quot;</span><span class=\"p\">,</span> <span class=\"s2\">&quot;DVD&quot;</span><span class=\"p\">),</span>\n        <span class=\"p\">),</span>\n    <span class=\"p\">),</span>\n    <span class=\"p\">(</span><span class=\"s2\">&quot;unknown&quot;</span><span class=\"p\">,</span> <span class=\"s2\">&quot;Unknown&quot;</span><span class=\"p\">),</span>\n<span class=\"p\">]</span>\n</code></pre></div>\n<p>Note that choices can be any sequence object -- not necessarily a list or\ntuple. This lets you construct choices dynamically. But if you find yourself\nhacking <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> to be dynamic, you're probably better off using\na proper database table with 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> is\nmeant for static data that doesn't change much, if ever.</p>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">Catatan</p>\n<p>A new migration is created each time the order of <code class=\"docutils literal notranslate\">choices</code> changes.</p>\n</aside>\n<p>For each model field that has <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> set, Django will normalize\nthe choices to a list of 2-tuples and add a method to retrieve the\nhuman-readable name for the field's current value. See\n<a class=\"reference internal\" href=\"/id/6.0/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> in the database API\ndocumentation.</p>\n<p id=\"field-choices-blank-label\">meskipun <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> disetel pada bidang bersama <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> kemudian sebuah etiket mengandung <code class=\"docutils literal notranslate\">&quot;---------&quot;</code> akan dibangun dengan kotak pilihan. Untuk menimpa perilaku ini, tambah sebuah tuple pada <code class=\"docutils literal notranslate\">choices</code> mengandung <code class=\"docutils literal notranslate\">None</code>; misalnya <code class=\"docutils literal notranslate\">(None, 'Your String For Display')</code>. Cara lain, anda dapat menggunakan string kosong daripada <code class=\"docutils literal notranslate\">None</code> dimana ini masuk akal - sseperti pada <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 id=\"enumeration-types\">\n<span id=\"field-choices-enum-types\"></span><h4>Enumeration types<a class=\"heading-anchor\" href=\"#enumeration-types\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>In addition, Django provides enumeration types that you can subclass to define\nchoices in a concise way:</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.utils.translation</span> <span class=\"kn\">import</span> gettext_lazy <span class=\"k\">as</span> _\n\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    <span class=\"k\">class</span> <span class=\"nc\">YearInSchool</span><span class=\"p\">(</span>models<span class=\"o\">.</span>TextChoices<span class=\"p\">):</span>\n        FRESHMAN <span class=\"o\">=</span> <span class=\"s2\">&quot;FR&quot;</span><span class=\"p\">,</span> _<span class=\"p\">(</span><span class=\"s2\">&quot;Freshman&quot;</span><span class=\"p\">)</span>\n        SOPHOMORE <span class=\"o\">=</span> <span class=\"s2\">&quot;SO&quot;</span><span class=\"p\">,</span> _<span class=\"p\">(</span><span class=\"s2\">&quot;Sophomore&quot;</span><span class=\"p\">)</span>\n        JUNIOR <span class=\"o\">=</span> <span class=\"s2\">&quot;JR&quot;</span><span class=\"p\">,</span> _<span class=\"p\">(</span><span class=\"s2\">&quot;Junior&quot;</span><span class=\"p\">)</span>\n        SENIOR <span class=\"o\">=</span> <span class=\"s2\">&quot;SR&quot;</span><span class=\"p\">,</span> _<span class=\"p\">(</span><span class=\"s2\">&quot;Senior&quot;</span><span class=\"p\">)</span>\n        GRADUATE <span class=\"o\">=</span> <span class=\"s2\">&quot;GR&quot;</span><span class=\"p\">,</span> _<span class=\"p\">(</span><span class=\"s2\">&quot;Graduate&quot;</span><span class=\"p\">)</span>\n\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>YearInSchool<span class=\"p\">,</span>\n        default<span class=\"o\">=</span>YearInSchool<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>\n            <span class=\"bp\">self</span><span class=\"o\">.</span>YearInSchool<span class=\"o\">.</span>JUNIOR<span class=\"p\">,</span>\n            <span class=\"bp\">self</span><span class=\"o\">.</span>YearInSchool<span class=\"o\">.</span>SENIOR<span class=\"p\">,</span>\n        <span class=\"p\">}</span>\n</code></pre></div>\n<p>These work similar to <a class=\"reference external\" href=\"https://docs.python.org/3/library/enum.html#module-enum\" title=\"(di Python v3.14)\"><code class=\"xref py py-mod docutils literal notranslate\">enum</code></a> from Python's standard library, but with some\nmodifications:</p>\n<ul>\n<li><p>Enum member values are a tuple of arguments to use when constructing the\nconcrete data type. Django supports adding an extra string value to the end\nof this tuple to be used as the human-readable name, or <code class=\"docutils literal notranslate\">label</code>. The\n<code class=\"docutils literal notranslate\">label</code> can be a lazy translatable string. Thus, in most cases, the member\nvalue will be a <code class=\"docutils literal notranslate\">(value, label)</code> 2-tuple. See below for <a class=\"reference internal\" href=\"#field-choices-enum-subclassing\"><span class=\"std std-ref\">an example\nof subclassing choices</span></a> using a more complex\ndata type. If a tuple is not provided, or the last item is not a (lazy)\nstring, the <code class=\"docutils literal notranslate\">label</code> is <a class=\"reference internal\" href=\"#field-choices-enum-auto-label\"><span class=\"std std-ref\">automatically generated</span></a> from the member name.</p></li>\n<li><p>A <code class=\"docutils literal notranslate\">.label</code> property is added on values, to return the human-readable name.</p></li>\n<li><p>A number of custom properties are added to the enumeration classes --\n<code class=\"docutils literal notranslate\">.choices</code>, <code class=\"docutils literal notranslate\">.labels</code>, <code class=\"docutils literal notranslate\">.values</code>, and <code class=\"docutils literal notranslate\">.names</code> -- to make it easier\nto access lists of those separate parts of the enumeration.</p>\n<aside class=\"admonition admonition-warning\" role=\"note\">\n<p class=\"admonition-title\">Peringatan</p>\n<p>These property names cannot be used as member names as they would conflict.</p>\n</aside>\n</li>\n<li><p>The use of <a class=\"reference external\" href=\"https://docs.python.org/3/library/enum.html#enum.unique\" title=\"(di Python v3.14)\"><code class=\"xref py py-func docutils literal notranslate\">enum.unique()</code></a> is enforced to ensure that values cannot be\ndefined multiple times. This is unlikely to be expected in choices for a\nfield.</p></li>\n</ul>\n<p>Note that using <code class=\"docutils literal notranslate\">YearInSchool.SENIOR</code>, <code class=\"docutils literal notranslate\">YearInSchool['SENIOR']</code>, or\n<code class=\"docutils literal notranslate\">YearInSchool('SR')</code> to access or lookup enum members work as expected, as do\nthe <code class=\"docutils literal notranslate\">.name</code> and <code class=\"docutils literal notranslate\">.value</code> properties on the members.</p>\n<p id=\"field-choices-enum-auto-label\">If you don't need to have the human-readable names translated, you can have\nthem inferred from the member name (replacing underscores with spaces and using\ntitle-case):</p>\n<div class=\"code-block\" data-language=\"pycon\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python console</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=\"Python console code\"><code><span class=\"gp\">&gt;&gt;&gt; </span><span class=\"k\">class</span> <span class=\"nc\">Vehicle</span><span class=\"p\">(</span>models<span class=\"o\">.</span>TextChoices<span class=\"p\">):</span>\n<span class=\"gp\">... </span>    CAR <span class=\"o\">=</span> <span class=\"s2\">&quot;C&quot;</span>\n<span class=\"gp\">... </span>    TRUCK <span class=\"o\">=</span> <span class=\"s2\">&quot;T&quot;</span>\n<span class=\"gp\">... </span>    JET_SKI <span class=\"o\">=</span> <span class=\"s2\">&quot;J&quot;</span>\n<span class=\"gp\">...</span>\n<span class=\"gp\">&gt;&gt;&gt; </span>Vehicle<span class=\"o\">.</span>JET_SKI<span class=\"o\">.</span>label\n<span class=\"go\">&#39;Jet Ski&#39;</span>\n</code></pre></div>\n<p>Since the case where the enum values need to be integers is extremely common,\nDjango provides an <code class=\"docutils literal notranslate\">IntegerChoices</code> class. 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\">Card</span><span class=\"p\">(</span>models<span class=\"o\">.</span>Model<span class=\"p\">):</span>\n    <span class=\"k\">class</span> <span class=\"nc\">Suit</span><span class=\"p\">(</span>models<span class=\"o\">.</span>IntegerChoices<span class=\"p\">):</span>\n        DIAMOND <span class=\"o\">=</span> <span class=\"mi\">1</span>\n        SPADE <span class=\"o\">=</span> <span class=\"mi\">2</span>\n        HEART <span class=\"o\">=</span> <span class=\"mi\">3</span>\n        CLUB <span class=\"o\">=</span> <span class=\"mi\">4</span>\n\n    suit <span class=\"o\">=</span> models<span class=\"o\">.</span>IntegerField<span class=\"p\">(</span>choices<span class=\"o\">=</span>Suit<span class=\"p\">)</span>\n</code></pre></div>\n<p>It is also possible to make use of the <a class=\"reference external\" href=\"https://docs.python.org/3/howto/enum.html#functional-api\">Enum Functional API</a> with the caveat\nthat labels are automatically generated as highlighted above:</p>\n<div class=\"code-block\" data-language=\"pycon\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python console</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=\"Python console code\"><code><span class=\"gp\">&gt;&gt;&gt; </span>MedalType <span class=\"o\">=</span> models<span class=\"o\">.</span>TextChoices<span class=\"p\">(</span><span class=\"s2\">&quot;MedalType&quot;</span><span class=\"p\">,</span> <span class=\"s2\">&quot;GOLD SILVER BRONZE&quot;</span><span class=\"p\">)</span>\n<span class=\"gp\">&gt;&gt;&gt; </span>MedalType<span class=\"o\">.</span>choices\n<span class=\"go\">[(&#39;GOLD&#39;, &#39;Gold&#39;), (&#39;SILVER&#39;, &#39;Silver&#39;), (&#39;BRONZE&#39;, &#39;Bronze&#39;)]</span>\n<span class=\"gp\">&gt;&gt;&gt; </span>Place <span class=\"o\">=</span> models<span class=\"o\">.</span>IntegerChoices<span class=\"p\">(</span><span class=\"s2\">&quot;Place&quot;</span><span class=\"p\">,</span> <span class=\"s2\">&quot;FIRST SECOND THIRD&quot;</span><span class=\"p\">)</span>\n<span class=\"gp\">&gt;&gt;&gt; </span>Place<span class=\"o\">.</span>choices\n<span class=\"go\">[(1, &#39;First&#39;), (2, &#39;Second&#39;), (3, &#39;Third&#39;)]</span>\n</code></pre></div>\n<p id=\"field-choices-enum-subclassing\">If you require support for a concrete data type other than <code class=\"docutils literal notranslate\">int</code> or <code class=\"docutils literal notranslate\">str</code>,\nyou can subclass <code class=\"docutils literal notranslate\">Choices</code> and the required concrete data type, e.g.\n<a class=\"reference external\" href=\"https://docs.python.org/3/library/datetime.html#datetime.date\" title=\"(di Python v3.14)\"><code class=\"xref py py-class docutils literal notranslate\">date</code></a> for use with <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<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\">MoonLandings</span><span class=\"p\">(</span>datetime<span class=\"o\">.</span>date<span class=\"p\">,</span> models<span class=\"o\">.</span>Choices<span class=\"p\">):</span>\n    APOLLO_11 <span class=\"o\">=</span> <span class=\"mi\">1969</span><span class=\"p\">,</span> <span class=\"mi\">7</span><span class=\"p\">,</span> <span class=\"mi\">20</span><span class=\"p\">,</span> <span class=\"s2\">&quot;Apollo 11 (Eagle)&quot;</span>\n    APOLLO_12 <span class=\"o\">=</span> <span class=\"mi\">1969</span><span class=\"p\">,</span> <span class=\"mi\">11</span><span class=\"p\">,</span> <span class=\"mi\">19</span><span class=\"p\">,</span> <span class=\"s2\">&quot;Apollo 12 (Intrepid)&quot;</span>\n    APOLLO_14 <span class=\"o\">=</span> <span class=\"mi\">1971</span><span class=\"p\">,</span> <span class=\"mi\">2</span><span class=\"p\">,</span> <span class=\"mi\">5</span><span class=\"p\">,</span> <span class=\"s2\">&quot;Apollo 14 (Antares)&quot;</span>\n    APOLLO_15 <span class=\"o\">=</span> <span class=\"mi\">1971</span><span class=\"p\">,</span> <span class=\"mi\">7</span><span class=\"p\">,</span> <span class=\"mi\">30</span><span class=\"p\">,</span> <span class=\"s2\">&quot;Apollo 15 (Falcon)&quot;</span>\n    APOLLO_16 <span class=\"o\">=</span> <span class=\"mi\">1972</span><span class=\"p\">,</span> <span class=\"mi\">4</span><span class=\"p\">,</span> <span class=\"mi\">21</span><span class=\"p\">,</span> <span class=\"s2\">&quot;Apollo 16 (Orion)&quot;</span>\n    APOLLO_17 <span class=\"o\">=</span> <span class=\"mi\">1972</span><span class=\"p\">,</span> <span class=\"mi\">12</span><span class=\"p\">,</span> <span class=\"mi\">11</span><span class=\"p\">,</span> <span class=\"s2\">&quot;Apollo 17 (Challenger)&quot;</span>\n</code></pre></div>\n<p>There are some additional caveats to be aware of:</p>\n<ul>\n<li><p>Enumeration types do not support <a class=\"reference internal\" href=\"#field-choices-named-groups\"><span class=\"std std-ref\">named groups</span></a>.</p></li>\n<li><p>Because an enumeration with a concrete data type requires all values to match\nthe type, overriding the <a class=\"reference internal\" href=\"#field-choices-blank-label\"><span class=\"std std-ref\">blank label</span></a>\ncannot be achieved by creating a member with a value of <code class=\"docutils literal notranslate\">None</code>. Instead,\nset the <code class=\"docutils literal notranslate\">__empty__</code> attribute on the class:</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\">Answer</span><span class=\"p\">(</span>models<span class=\"o\">.</span>IntegerChoices<span class=\"p\">):</span>\n    NO <span class=\"o\">=</span> <span class=\"mi\">0</span><span class=\"p\">,</span> _<span class=\"p\">(</span><span class=\"s2\">&quot;No&quot;</span><span class=\"p\">)</span>\n    YES <span class=\"o\">=</span> <span class=\"mi\">1</span><span class=\"p\">,</span> _<span class=\"p\">(</span><span class=\"s2\">&quot;Yes&quot;</span><span class=\"p\">)</span>\n\n    __empty__ <span class=\"o\">=</span> _<span class=\"p\">(</span><span class=\"s2\">&quot;(Unknown)&quot;</span><span class=\"p\">)</span>\n</code></pre></div>\n</li>\n</ul>\n</section>\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>Nama dari kolom basisdata untuk digunakan pada bidang ini. jika tidak diberikan, Django akan menggunakan nama bidang.</p>\n<p>Jika nama kolom basisdata anda adalah kata disiapkan SQL, atau mengandung karakter yang tidak diizinkan dalam nama variabel Python -- terutama, tanda penghubung -- itu juga OK. Django mengutip nama kolom dan tabel dinelakang layar.</p>\n</section>\n<section id=\"db-comment\">\n<h3><code class=\"docutils literal notranslate\">db_comment</code><a class=\"heading-anchor\" href=\"#db-comment\"><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_comment\">\n<span class=\"sig-prename descclassname\">Field.</span><span class=\"sig-name descname\">db_comment</span><a class=\"heading-anchor\" href=\"#django.db.models.Field.db_comment\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>The comment on the database column to use for this field. It is useful for\ndocumenting fields for individuals with direct database access who may not be\nlooking at your Django code. 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>pub_date <span class=\"o\">=</span> models<span class=\"o\">.</span>DateTimeField<span class=\"p\">(</span>\n    db_comment<span class=\"o\">=</span><span class=\"s2\">&quot;Date and time when the article was published&quot;</span><span class=\"p\">,</span>\n<span class=\"p\">)</span>\n</code></pre></div>\n</section>\n<section id=\"db-default\">\n<h3><code class=\"docutils literal notranslate\">db_default</code><a class=\"heading-anchor\" href=\"#db-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.db_default\">\n<span class=\"sig-prename descclassname\">Field.</span><span class=\"sig-name descname\">db_default</span><a class=\"heading-anchor\" href=\"#django.db.models.Field.db_default\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>The database-computed default value for this field. This can be a literal value\nor a database function, such as <a class=\"reference internal\" href=\"/id/6.0/ref/models/database-functions/#django.db.models.functions.Now\" title=\"django.db.models.functions.Now\"><code class=\"xref py py-class docutils literal notranslate\">Now</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>created <span class=\"o\">=</span> models<span class=\"o\">.</span>DateTimeField<span class=\"p\">(</span>db_default<span class=\"o\">=</span>Now<span class=\"p\">())</span>\n</code></pre></div>\n<p>More complex expressions can be used, as long as they are made from literals\nand database functions:</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>month_due <span class=\"o\">=</span> models<span class=\"o\">.</span>DateField<span class=\"p\">(</span>\n    db_default<span class=\"o\">=</span>TruncMonth<span class=\"p\">(</span>\n        Now<span class=\"p\">()</span> <span class=\"o\">+</span> timedelta<span class=\"p\">(</span>days<span class=\"o\">=</span><span class=\"mi\">90</span><span class=\"p\">),</span>\n        output_field<span class=\"o\">=</span>models<span class=\"o\">.</span>DateField<span class=\"p\">(),</span>\n    <span class=\"p\">)</span>\n<span class=\"p\">)</span>\n</code></pre></div>\n<p>Database defaults cannot reference other fields or models. For example, this is\ninvalid:</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>end <span class=\"o\">=</span> models<span class=\"o\">.</span>IntegerField<span class=\"p\">(</span>db_default<span class=\"o\">=</span>F<span class=\"p\">(</span><span class=\"s2\">&quot;start&quot;</span><span class=\"p\">)</span> <span class=\"o\">+</span> <span class=\"mi\">50</span><span class=\"p\">)</span>\n</code></pre></div>\n<p>If both <code class=\"docutils literal notranslate\">db_default</code> and <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> are set, <code class=\"docutils literal notranslate\">default</code> will take\nprecedence when creating instances in Python code. <code class=\"docutils literal notranslate\">db_default</code> will still be\nset at the database level and will be used when inserting rows outside of the\nORM or when adding a new field in a migration.</p>\n<p>If a field has a <code class=\"docutils literal notranslate\">db_default</code> without a <code class=\"docutils literal notranslate\">default</code> set and no value is\nassigned to the field, a <code class=\"docutils literal notranslate\">DatabaseDefault</code> object is returned as the field\nvalue on unsaved model instances. The actual value for the field is determined\nby the database when the model instance is saved.</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>Jika``True``, indeks basisdata akan dibuat untuk bidang ini.</p>\n<aside class=\"admonition-use-the-attr-options-indexes-option-instead admonition\" role=\"note\">\n<p class=\"admonition-title\">Gunakan pilihan <a class=\"reference internal\" href=\"/id/6.0/ref/models/options/#django.db.models.Options.indexes\" title=\"django.db.models.Options.indexes\"><code class=\"xref py py-attr docutils literal notranslate\">indexes</code></a> sebagai gantinya.</p>\n<p>Where possible, use the <a class=\"reference internal\" href=\"/id/6.0/ref/models/options/#django.db.models.Options.indexes\" title=\"django.db.models.Options.indexes\"><code class=\"xref py py-attr docutils literal notranslate\">Meta.indexes</code></a> option\ninstead. In nearly all cases, <a class=\"reference internal\" href=\"/id/6.0/ref/models/options/#django.db.models.Options.indexes\" title=\"django.db.models.Options.indexes\"><code class=\"xref py py-attr docutils literal notranslate\">indexes</code></a> provides more\nfunctionality than <code class=\"docutils literal notranslate\">db_index</code>. <code class=\"docutils literal notranslate\">db_index</code> may be deprecated in the\nfuture.</p>\n</aside>\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>Nama dari <a class=\"reference internal\" href=\"/id/6.0/topics/db/tablespaces/\"><span class=\"doc\">database tablespace</span></a> untuk digunakan untuk indeks bidang ini, jika bidang ini diindeks. Awalan adalah pengaturan <a class=\"reference internal\" href=\"/id/6.0/ref/settings/#std-setting-DEFAULT_INDEX_TABLESPACE\"><code class=\"xref std std-setting docutils literal notranslate\">DEFAULT_INDEX_TABLESPACE</code></a> proyek, jika disetel, atau <a class=\"reference internal\" href=\"/id/6.0/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> dari model, jika ada. Jika backendtidak mendukung tablespace untuk pengindeksan, pilihan ini diabaikan.</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>Nilai awalan untuk bidang. Ini dapat berupa nilai atau obyek callable. Jika callable itu akan dipanggil setiap waktu obyek baru dibuat.</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>,\netc.), as a reference to the same instance of that object would be used as the\ndefault value in all new model instances. Instead, wrap the desired default in\na callable. For example, if you want to specify a default <code class=\"docutils literal notranslate\">dict</code> for\n<a class=\"reference internal\" href=\"#django.db.models.JSONField\" title=\"django.db.models.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\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=\"/id/6.0/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<p>The default value can also be set at the database level with\n<a class=\"reference internal\" href=\"#django.db.models.Field.db_default\" title=\"django.db.models.Field.db_default\"><code class=\"xref py py-attr docutils literal notranslate\">Field.db_default</code></a>.</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=\"/id/6.0/topics/forms/modelforms/#django.forms.ModelForm\" title=\"django.forms.ModelForm\"><code class=\"xref py py-class docutils literal notranslate\">ModelForm</code></a>. It will also be skipped during <a class=\"reference internal\" href=\"/id/6.0/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\nyou want to override.</p>\n<p>Kunci-kunci pesan kesalahan termasuk <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>, <code class=\"docutils literal notranslate\">unique</code>, dan <code class=\"docutils literal notranslate\">unique_for_date</code>. Kunci-kunci pesan kesalahan tambahan ditentukan untuk setiap bidang dalam bagian <a class=\"reference internal\" href=\"#field-types\">Field types</a> dibawah.</p>\n<p>Pesan-pesan kesalahan ini sering tidak menyebarkan ke formulir. Lihat <a class=\"reference internal\" href=\"/id/6.0/topics/forms/modelforms/#considerations-regarding-model-errormessages\"><span class=\"std std-ref\">Pertimbangan mengenai error_messages model</span></a>.</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>Teks &quot;help&quot; tambahan untuk ditampilkan dengan widget formulir. Itu sangat berguna untuk dokumentasi bahkan jika bidang anda tidak digunakan pada formulir.</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<a class=\"reference internal\" href=\"/id/6.0/ref/utils/#django.utils.html.escape\" title=\"django.utils.html.escape\"><code class=\"xref py py-func docutils literal notranslate\">django.utils.html.escape()</code></a> 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>Jika <code class=\"docutils literal notranslate\">True</code>, bidang ini adalah primary key untuk model.</p>\n<p>If you don't specify <code class=\"docutils literal notranslate\">primary_key=True</code> for any field in your model and have\nnot defined a composite primary key, Django will automatically add a field to\nhold the primary key. So, you don't need to set <code class=\"docutils literal notranslate\">primary_key=True</code> on any of\nyour fields unless you want to override the default primary-key behavior. The\ntype of auto-created primary key fields can be specified per app in\n<a class=\"reference internal\" href=\"/id/6.0/ref/applications/#django.apps.AppConfig.default_auto_field\" title=\"django.apps.AppConfig.default_auto_field\"><code class=\"xref py py-attr docutils literal notranslate\">AppConfig.default_auto_field</code></a>\nor globally in the <a class=\"reference internal\" href=\"/id/6.0/ref/settings/#std-setting-DEFAULT_AUTO_FIELD\"><code class=\"xref std std-setting docutils literal notranslate\">DEFAULT_AUTO_FIELD</code></a> setting. For more, see\n<a class=\"reference internal\" href=\"/id/6.0/topics/db/models/#automatic-primary-key-fields\"><span class=\"std std-ref\">Bidang primary key otomatis</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 field per model can set\n<code class=\"docutils literal notranslate\">primary_key=True</code>. Composite primary keys must be defined using\n<a class=\"reference internal\" href=\"#django.db.models.CompositePrimaryKey\" title=\"django.db.models.CompositePrimaryKey\"><code class=\"xref py py-class docutils literal notranslate\">CompositePrimaryKey</code></a> instead of setting this flag to <code class=\"docutils literal notranslate\">True</code> for all\nfields to maintain this invariant.</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<p>The primary key field is set to <code class=\"docutils literal notranslate\">None</code> when\n<a class=\"reference internal\" href=\"/id/6.0/ref/models/instances/#django.db.models.Model.delete\" title=\"django.db.models.Model.delete\"><code class=\"xref py py-meth docutils literal notranslate\">deleting</code></a> an object.</p>\n<aside class=\"version-note version-changed\" data-version=\"5.2\" role=\"note\">\n<p class=\"version-note-title\">Changed in Django 5.2</p><p>The <code class=\"docutils literal notranslate\">CompositePrimaryKey</code> field was added.</p>\n</aside>\n</section>\n<section id=\"unique\">\n<h3><code class=\"docutils literal notranslate\">unik</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>Jika <code class=\"docutils literal notranslate\">True</code>, bidang ini harus unik diseluruh tabel.</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=\"/id/6.0/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=\"/id/6.0/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>Pilihan ini adalah adalah sah pada semua jenis bidang kecuali <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> dan <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>.</p>\n<p>Catat bahwa ketika <code class=\"docutils literal notranslate\">unique</code> adalah <code class=\"docutils literal notranslate\">True</code>, anda tidak butuh menentukan <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>, karena <code class=\"docutils literal notranslate\">unique</code> menyiratkan pembuatan dari sebuah indeks.</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>Setel ini ke nama dari  <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> atau <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> untuk membutuhkan dimana bidang ini unik untuk nilai dari bidang tanggal.</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=\"/id/6.0/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=\"/id/6.0/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=\"/id/6.0/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=\"/id/6.0/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=\"/id/6.0/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>Seperti <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>, tetapi membutuhkan bidang unik dengan mematuhi pada bulan.</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>Seperti <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> dan <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=\"/id/6.0/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>Sebuah list dari pengesah untuk berjalan untuk bidang ini. Lihat <a class=\"reference internal\" href=\"/id/6.0/ref/validators/\"><span class=\"doc\">validators documentation</span></a> untuk informasi lebih.</p>\n</section>\n</section>\n<section id=\"field-types\">\n<span id=\"model-field-types\"></span><h2>Jenis bidang<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>An <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> that automatically increments according to available\nIDs. You usually won't need to use this directly; a primary key field will\nautomatically be added to your model if you don't specify otherwise. See\n<a class=\"reference internal\" href=\"/id/6.0/topics/db/models/#automatic-primary-key-fields\"><span class=\"std std-ref\">Bidang primary key otomatis</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<p>Integer 64-bit, seperti <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> kecuali itu dijamin untuk cocok nomor dari <code class=\"docutils literal notranslate\">1</code> sampai <code class=\"docutils literal notranslate\">9223372036854775807</code>.</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>A 64-bit integer, much like an <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> except that it is\nguaranteed to fit numbers from <code class=\"docutils literal notranslate\">-9223372036854775808</code> to\n<code class=\"docutils literal notranslate\">9223372036854775807</code>. The default form widget for this field is a\n<a class=\"reference internal\" href=\"/id/6.0/ref/forms/widgets/#django.forms.NumberInput\" title=\"django.forms.NumberInput\"><code class=\"xref py py-class docutils literal notranslate\">NumberInput</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\">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.BinaryField\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>Sebuah bidang untuk menyimpan data binder mentah. Itu dapat diberikan <a class=\"reference external\" href=\"https://docs.python.org/3/library/stdtypes.html#bytes\" title=\"(di Python v3.14)\"><code class=\"xref py py-class docutils literal notranslate\">bytes</code></a>, <a class=\"reference external\" href=\"https://docs.python.org/3/library/stdtypes.html#bytearray\" title=\"(di Python v3.14)\"><code class=\"xref py py-class docutils literal notranslate\">bytearray</code></a>, atau <a class=\"reference external\" href=\"https://docs.python.org/3/library/stdtypes.html#memoryview\" title=\"(di Python v3.14)\"><code class=\"xref py py-class docutils literal notranslate\">memoryview</code></a>.</p>\n<p>Secara awalan, <code class=\"docutils literal notranslate\">BinaryField</code> menyetel <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</code></a> menjadi <code class=\"docutils literal notranslate\">False</code>, dalam kasus itu tidak dapat disertakan dalam <a class=\"reference internal\" href=\"/id/6.0/topics/forms/modelforms/#django.forms.ModelForm\" title=\"django.forms.ModelForm\"><code class=\"xref py py-class docutils literal notranslate\">ModelForm</code></a>.</p>\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.BinaryField.max_length\">\n<span class=\"sig-prename descclassname\">BinaryField.</span><span class=\"sig-name descname\">max_length</span><a class=\"heading-anchor\" href=\"#django.db.models.BinaryField.max_length\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Optional. The maximum length (in bytes) of the field. The maximum length is\nenforced in Django's validation using\n<a class=\"reference internal\" href=\"/id/6.0/ref/validators/#django.core.validators.MaxLengthValidator\" title=\"django.core.validators.MaxLengthValidator\"><code class=\"xref py py-class docutils literal notranslate\">MaxLengthValidator</code></a>.</p>\n</dd></dl>\n\n<aside class=\"admonition-abusing-binaryfield admonition\" role=\"note\">\n<p class=\"admonition-title\">Menyalahgunakan <code class=\"docutils literal notranslate\">BinaryField</code></p>\n<p>Meskipun anda mungkin berpikir tentang menyimpan berkas-berkas dalam basisdata, pertimbangkan bahwa itu adalah rancangan buruh dalam 99% dari kasus. Bidang ini <em>bukan</em> sebuah penggantian untuk penangangan <a class=\"reference internal\" href=\"/id/6.0/howto/static-files/\"><span class=\"doc\">static files</span></a> yang sesuai.</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>Sebuah bidang true/false.</p>\n<p>Widget formulir awalan untuk bidang ini adalah <a class=\"reference internal\" href=\"/id/6.0/ref/forms/widgets/#django.forms.CheckboxInput\" title=\"django.forms.CheckboxInput\"><code class=\"xref py py-class docutils literal notranslate\">CheckboxInput</code></a>, atau <a class=\"reference internal\" href=\"/id/6.0/ref/forms/widgets/#django.forms.NullBooleanSelect\" title=\"django.forms.NullBooleanSelect\"><code class=\"xref py py-class docutils literal notranslate\">NullBooleanSelect</code></a> jika <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=True</code></a>.</p>\n<p>Nilai awal dari <code class=\"docutils literal notranslate\">BooleanField</code> adalah <code class=\"docutils literal notranslate\">None</code> ketika <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> belum ditentukan.</p>\n</section>\n<section id=\"compositeprimarykey\">\n<h3><code class=\"docutils literal notranslate\">CompositePrimaryKey</code><a class=\"heading-anchor\" href=\"#compositeprimarykey\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<aside class=\"version-note version-added\" data-version=\"5.2\" role=\"note\">\n<p class=\"version-note-title\">New in Django 5.2</p></aside>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.CompositePrimaryKey\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">CompositePrimaryKey</span><span class=\"sig-paren\">(</span><em class=\"sig-param\"><span class=\"o\">*</span>field_names</em>, <em class=\"sig-param\"><span class=\"o\">**</span>options</em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.db.models.CompositePrimaryKey\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>A virtual field used for defining a composite primary key.</p>\n<p>This field must be defined as the model's <code class=\"docutils literal notranslate\">pk</code> attribute. If present, Django\nwill create the underlying model table with a composite primary key.</p>\n<p>The <code class=\"docutils literal notranslate\">*field_names</code> argument is a list of positional field names that compose\nthe primary key.</p>\n<p>See <a class=\"reference internal\" href=\"/id/6.0/topics/composite-primary-key/\"><span class=\"doc\">Composite primary keys</span></a> for more details.</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>Bidang string, untuk string ukuran-kecil- sampai-besar.</p>\n<p>Untuk teks besar, gunakan <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>Widget formulir awalan untuk bidang ini adalah <a class=\"reference internal\" href=\"/id/6.0/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> has the following extra arguments:</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>The maximum length (in characters) of the field. The <code class=\"docutils literal notranslate\">max_length</code>\nis enforced at the database level and in Django's validation using\n<a class=\"reference internal\" href=\"/id/6.0/ref/validators/#django.core.validators.MaxLengthValidator\" title=\"django.core.validators.MaxLengthValidator\"><code class=\"xref py py-class docutils literal notranslate\">MaxLengthValidator</code></a>. It's required for all\ndatabase backends included with Django except PostgreSQL and SQLite, which\nsupports unlimited <code class=\"docutils literal notranslate\">VARCHAR</code> columns.</p>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">Catatan</p>\n<p>Jika anda sedang menulis sebuah aplikasi yang harus dihubungkan ke banyak backend basisdata, anda harus waspada bahwa ada pembatasan pada <code class=\"docutils literal notranslate\">max_length</code> untuk beberapa backend. Mengacu pada <a class=\"reference internal\" href=\"/id/6.0/ref/databases/\"><span class=\"doc\">database backend notes</span></a> untuk rincian.</p>\n</aside>\n<aside class=\"version-note version-changed\" data-version=\"5.2\" role=\"note\">\n<p class=\"version-note-title\">Changed in Django 5.2</p><p>Support for unlimited <code class=\"docutils literal notranslate\">VARCHAR</code> columns was added on SQLite.</p>\n</aside>\n</dd></dl>\n\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.CharField.db_collation\">\n<span class=\"sig-prename descclassname\">CharField.</span><span class=\"sig-name descname\">db_collation</span><a class=\"heading-anchor\" href=\"#django.db.models.CharField.db_collation\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Optional. The database collation name of the field.</p>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">Catatan</p>\n<p>Collation names are not standardized. As such, this will not be\nportable across multiple database backends.</p>\n</aside>\n<aside class=\"admonition-oracle admonition\" role=\"note\">\n<p class=\"admonition-title\">Oracle</p>\n<p>Oracle supports collations only when the <code class=\"docutils literal notranslate\">MAX_STRING_SIZE</code> database\ninitialization parameter is set to <code class=\"docutils literal notranslate\">EXTENDED</code>.</p>\n</aside>\n</dd></dl>\n\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>Tanggal, diwakilkan dalam Python oleh instance <code class=\"docutils literal notranslate\">datetime.date</code>. mempunyai beberapa tambahan, argumen pilihan:</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>Automatically set the field to now every time the object is saved. Useful\nfor &quot;last-modified&quot; timestamps. Note that the current date is <em>always</em>\nused; it's not just a default value that you can override.</p>\n<p>The field is only automatically updated when calling <a class=\"reference internal\" href=\"/id/6.0/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>. The field isn't updated when making updates\nto other fields in other ways such as <a class=\"reference internal\" href=\"/id/6.0/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>, though you can specify a custom\nvalue for the field in an update like that.</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>Automatically set the field to now when the object is first created. Useful\nfor creation of timestamps. Note that the current date is <em>always</em> used;\nit's not just a default value that you can override. So even if you\nset a value for this field when creating the object, it will be ignored.\nIf you want to be able to modify this field, set the following instead of\n<code class=\"docutils literal notranslate\">auto_now_add=True</code>:</p>\n<ul class=\"simple\">\n<li><p>Untuk <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> - dari <a class=\"reference external\" href=\"https://docs.python.org/3/library/datetime.html#datetime.date.today\" title=\"(di Python v3.14)\"><code class=\"xref py py-meth docutils literal notranslate\">datetime.date.today()</code></a></p></li>\n<li><p>Untuk <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> - dari <a class=\"reference internal\" href=\"/id/6.0/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>The default form widget for this field is a\n<a class=\"reference internal\" href=\"/id/6.0/ref/forms/widgets/#django.forms.DateInput\" title=\"django.forms.DateInput\"><code class=\"xref py py-class docutils literal notranslate\">DateInput</code></a>. The admin adds a JavaScript calendar,\nand a shortcut for &quot;Today&quot;. Includes an additional <code class=\"docutils literal notranslate\">invalid_date</code> error\nmessage key.</p>\n<p>Pilihan <code class=\"docutils literal notranslate\">auto_now_add</code>, <code class=\"docutils literal notranslate\">auto_now</code>, dan <code class=\"docutils literal notranslate\">default</code> saling ekslusif. Perpaduan apapun dari pilihan ini akan menghasilkan sebuah kesalahan.</p>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">Catatan</p>\n<p>Seperti saat ini diterapkan, mengatur <code class=\"docutils literal notranslate\">auto_now</code> atau <code class=\"docutils literal notranslate\">auto_now_add</code> menjadi <code class=\"docutils literal notranslate\">True</code> akan menyebabkan bidang memiliki setelan <code class=\"docutils literal notranslate\">editable=False</code> dan <code class=\"docutils literal notranslate\">blank=True</code>.</p>\n</aside>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">Catatan</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=\"/id/6.0/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 using your own callable default or overriding <code class=\"docutils literal notranslate\">save()</code> instead\nof using <code class=\"docutils literal notranslate\">auto_now</code> or <code class=\"docutils literal notranslate\">auto_now_add</code>; or using a <code class=\"docutils literal notranslate\">DateTimeField</code>\ninstead of a <code class=\"docutils literal notranslate\">DateField</code> and deciding how to handle the conversion from\ndatetime to date at display time.</p>\n</aside>\n<aside class=\"admonition admonition-warning\" role=\"note\">\n<p class=\"admonition-title\">Peringatan</p>\n<p>Always use <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> with a <code class=\"docutils literal notranslate\">datetime.date</code> instance.</p>\n<p>If you have a <code class=\"docutils literal notranslate\">datetime.datetime</code> instance, it's recommended to convert\nit to a <code class=\"docutils literal notranslate\">datetime.date</code> first. If you don't, <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> will\nlocalize the <code class=\"docutils literal notranslate\">datetime.datetime</code> to the <a class=\"reference internal\" href=\"/id/6.0/topics/i18n/timezones/#default-current-time-zone\"><span class=\"std std-ref\">default timezone</span></a> and convert it to a <code class=\"docutils literal notranslate\">datetime.date</code>\ninstance, removing its time component. This is true for both storage and\ncomparison.</p>\n</aside>\n<aside class=\"admonition admonition-warning\" role=\"note\">\n<p class=\"admonition-title\">Peringatan</p>\n<p>On PostgreSQL and MySQL, arithmetic operations on a <code class=\"docutils literal notranslate\">DateField</code> with a\n<a class=\"reference external\" href=\"https://docs.python.org/3/library/datetime.html#datetime.timedelta\" title=\"(di Python v3.14)\"><code class=\"xref py py-class docutils literal notranslate\">timedelta</code></a> return a <code class=\"docutils literal notranslate\">datetime</code> instead of a <code class=\"docutils literal notranslate\">date</code>.\nThis occurs because Python's <code class=\"docutils literal notranslate\">timedelta</code> is converted to SQL\n<code class=\"docutils literal notranslate\">INTERVAL</code>, and the SQL operation <code class=\"docutils literal notranslate\">date +/- interval</code> returns a\n<code class=\"docutils literal notranslate\">timestamp</code> on these databases.</p>\n<p>To ensure a <code class=\"docutils literal notranslate\">date</code> result, use one of the following approaches. Either\nexplicitly cast the result to a date:</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\">datetime</span>\n<span class=\"kn\">from</span> <span class=\"nn\">django.db.models</span> <span class=\"kn\">import</span> DateField<span class=\"p\">,</span> F\n<span class=\"kn\">from</span> <span class=\"nn\">django.db.models.functions</span> <span class=\"kn\">import</span> Cast\n\nqs <span class=\"o\">=</span> MyModel<span class=\"o\">.</span>objects<span class=\"o\">.</span>annotate<span class=\"p\">(</span>\n    previous_day<span class=\"o\">=</span>Cast<span class=\"p\">(</span>\n        F<span class=\"p\">(</span><span class=\"s2\">&quot;date_field&quot;</span><span class=\"p\">)</span> <span class=\"o\">-</span> datetime<span class=\"o\">.</span>timedelta<span class=\"p\">(</span>days<span class=\"o\">=</span><span class=\"mi\">1</span><span class=\"p\">),</span>\n        output_field<span class=\"o\">=</span>DateField<span class=\"p\">(),</span>\n    <span class=\"p\">)</span>\n<span class=\"p\">)</span>\n</code></pre></div>\n<p>Or on PostgreSQL only, use integer arithmetic to represent days:</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.models</span> <span class=\"kn\">import</span> DateField<span class=\"p\">,</span> ExpressionWrapper<span class=\"p\">,</span> F\n\nqs <span class=\"o\">=</span> MyModel<span class=\"o\">.</span>objects<span class=\"o\">.</span>annotate<span class=\"p\">(</span>\n    previous_day<span class=\"o\">=</span>ExpressionWrapper<span class=\"p\">(</span>\n        F<span class=\"p\">(</span><span class=\"s2\">&quot;date_field&quot;</span><span class=\"p\">)</span> <span class=\"o\">-</span> <span class=\"mi\">1</span><span class=\"p\">,</span>  <span class=\"c1\"># Subtract 1 day as integer</span>\n        output_field<span class=\"o\">=</span>DateField<span class=\"p\">(),</span>\n    <span class=\"p\">)</span>\n<span class=\"p\">)</span>\n</code></pre></div>\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>Sebuah tanggal dan waktu, diwakili dalam Python oleh sebuah contoh <code class=\"docutils literal notranslate\">datetime.datetime</code>. Mengambil tambahan argumen sama sebagai <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>The default form widget for this field is a single\n<a class=\"reference internal\" href=\"/id/6.0/ref/forms/widgets/#django.forms.DateTimeInput\" title=\"django.forms.DateTimeInput\"><code class=\"xref py py-class docutils literal notranslate\">DateTimeInput</code></a>. The admin uses two separate\n<a class=\"reference internal\" href=\"/id/6.0/ref/forms/widgets/#django.forms.TextInput\" title=\"django.forms.TextInput\"><code class=\"xref py py-class docutils literal notranslate\">TextInput</code></a> widgets with JavaScript shortcuts.</p>\n<aside class=\"admonition admonition-warning\" role=\"note\">\n<p class=\"admonition-title\">Peringatan</p>\n<p>Always use <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> with a <code class=\"docutils literal notranslate\">datetime.datetime</code>\ninstance.</p>\n<p>If you have a <code class=\"docutils literal notranslate\">datetime.date</code> instance, it's recommended to convert it to\na <code class=\"docutils literal notranslate\">datetime.datetime</code> first. If you don't, <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> will\nuse midnight in the <a class=\"reference internal\" href=\"/id/6.0/topics/i18n/timezones/#default-current-time-zone\"><span class=\"std std-ref\">default timezone</span></a> for\nthe time component. This is true for both storage and comparison. To\ncompare the date portion of 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> with a\n<code class=\"docutils literal notranslate\">datetime.date</code> instance, use the <a class=\"reference internal\" href=\"/id/6.0/ref/models/querysets/#std-fieldlookup-date\"><code class=\"xref std std-lookup docutils literal notranslate\">date</code></a> lookup.</p>\n</aside>\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>A fixed-precision decimal number, represented in Python by a\n<a class=\"reference external\" href=\"https://docs.python.org/3/library/decimal.html#decimal.Decimal\" title=\"(di Python v3.14)\"><code class=\"xref py py-class docutils literal notranslate\">Decimal</code></a> instance. It validates the input using\n<a class=\"reference internal\" href=\"/id/6.0/ref/validators/#django.core.validators.DecimalValidator\" title=\"django.core.validators.DecimalValidator\"><code class=\"xref py py-class docutils literal notranslate\">DecimalValidator</code></a>.</p>\n<p>Has the following <strong>required</strong> arguments:</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>Angka maksimal dari bilangan diizinkan dalam angka. Catat bahwa angka ini harus lebih besar dari atau setara pada <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>Sejumlah tempat desiman untuk menyimpan dengan nomor.</p>\n</dd></dl>\n\n<p>For example, to store numbers up to <code class=\"docutils literal notranslate\">999.99</code> with a resolution of 2 decimal\nplaces, you'd 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>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>Dan untuk menyimpan angka sampai pada sekitar satu milyar dengan sebuah keputusan dari 10 tempat desimal:</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>Widget formulir awalan untuk bidang ini adalah sebuah <a class=\"reference internal\" href=\"/id/6.0/ref/forms/widgets/#django.forms.NumberInput\" title=\"django.forms.NumberInput\"><code class=\"xref py py-class docutils literal notranslate\">NumberInput</code></a> ketika <a class=\"reference internal\" href=\"/id/6.0/ref/forms/fields/#django.forms.Field.localize\" title=\"django.forms.Field.localize\"><code class=\"xref py py-attr docutils literal notranslate\">localize</code></a> adalah <code class=\"docutils literal notranslate\">False</code> atau <a class=\"reference internal\" href=\"/id/6.0/ref/forms/widgets/#django.forms.TextInput\" title=\"django.forms.TextInput\"><code class=\"xref py py-class docutils literal notranslate\">TextInput</code></a> sebaliknya.</p>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">Catatan</p>\n<p>For more information about the differences between the\n<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> and <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> classes, please\nsee <a class=\"reference internal\" href=\"#floatfield-vs-decimalfield\"><span class=\"std std-ref\">FloatField vs. DecimalField</span></a>. You\nshould also be aware of <a class=\"reference internal\" href=\"/id/6.0/ref/databases/#sqlite-decimal-handling\"><span class=\"std std-ref\">SQLite limitations</span></a>\nof decimal fields.</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>A field for storing periods of time - modeled in Python by\n<a class=\"reference external\" href=\"https://docs.python.org/3/library/datetime.html#datetime.timedelta\" title=\"(di Python v3.14)\"><code class=\"xref py py-class docutils literal notranslate\">timedelta</code></a>. When used on PostgreSQL, the data type\nused is an <code class=\"docutils literal notranslate\">interval</code> and on Oracle the data type is <code class=\"docutils literal notranslate\">INTERVAL DAY(9) TO\nSECOND(6)</code>. Otherwise a <code class=\"docutils literal notranslate\">bigint</code> of microseconds is used.</p>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">Catatan</p>\n<p>Arithmetic with <code class=\"docutils literal notranslate\">DurationField</code> works in most cases. However on all\ndatabases other than PostgreSQL, comparing the value of a <code class=\"docutils literal notranslate\">DurationField</code>\nto arithmetic on <code class=\"docutils literal notranslate\">DateTimeField</code> instances will not work as expected.</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>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> that checks that the value is a valid email address using\n<a class=\"reference internal\" href=\"/id/6.0/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\">''</span></em>, <em class=\"sig-param\">storage<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>Sebuah bidang berkas-unggah</p>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">Catatan</p>\n<p>Argumen <code class=\"docutils literal notranslate\">primary_key</code> tidak didukung dan akan memunculkan sebuah kesalahan jika digunakan.</p>\n</aside>\n<p>Has the following optional arguments:</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>This attribute provides a way of setting the upload directory and file\nname, and can be set in two ways. In both cases, the value is passed to the\n<a class=\"reference internal\" href=\"/id/6.0/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> method.</p>\n<p>If you specify a string value or a <a class=\"reference external\" href=\"https://docs.python.org/3/library/pathlib.html#pathlib.Path\" title=\"(di Python v3.14)\"><code class=\"xref py py-class docutils literal notranslate\">Path</code></a>, it may contain\n<a class=\"reference external\" href=\"https://docs.python.org/3/library/time.html#time.strftime\" title=\"(di Python v3.14)\"><code class=\"xref py py-func docutils literal notranslate\">strftime()</code></a> formatting, which will be replaced by the date/time\nof the file upload (so that uploaded files don't fill up the given\ndirectory). 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=\"s2\">&quot;uploads/&quot;</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=\"s2\">&quot;uploads/%Y/%m/</span><span class=\"si\">%d</span><span class=\"s2\">/&quot;</span><span class=\"p\">)</span>\n</code></pre></div>\n<p>If you are using the default\n<a class=\"reference internal\" href=\"/id/6.0/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=\"/id/6.0/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> mungkin juga dapat dipanggil, seperti sebuah fungsi. Ini akan dipanggil untuk mendapatkan jalur unggahan, termasuk nama berkas. Panggilan iniharus menerima dua argumen dan mengembalikan jalur gaya-Unix (dengan garis miring didepan) untuk dilewatkan bersama ke sistem penyimpanan. Dua argumen adalah:</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>Deskripsi</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>Di kebanyakan kasus, obyek ini tidak akan disimpan ke basisdata dulu, jadi jika itu menggunakan <code class=\"docutils literal notranslate\">AutoField</code> awal, <em>itu mungkin belum memiliki nilai untuk bidang primary key nya</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>Sebagai contoh:</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=\"s2\">&quot;user_</span><span class=\"si\">{0}</span><span class=\"s2\">/</span><span class=\"si\">{1}</span><span class=\"s2\">&quot;</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\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, or a callable which returns a storage object. This\nhandles the storage and retrieval of your files. See <a class=\"reference internal\" href=\"/id/6.0/topics/files/\"><span class=\"doc\">Mengelola berkas</span></a>\nfor details on how to provide this object.</p>\n</dd></dl>\n\n<p>Widget formulir awalan untuk bidang ini adalah <a class=\"reference internal\" href=\"/id/6.0/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>Menggunakan sebuah <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> atau sebuah <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> (lihat dibawah) dalam sebuah model mengambil beberapa langkah:</p>\n<ol class=\"arabic simple\">\n<li><p>Dalam berkas pengaturan anda, anda butuh menentukan <a class=\"reference internal\" href=\"/id/6.0/ref/settings/#std-setting-MEDIA_ROOT\"><code class=\"xref std std-setting docutils literal notranslate\">MEDIA_ROOT</code></a> sebagai jalur penuh ke direktori dimana anda ingin Django menyimpan berkas terunggah. (Untuk penampilan, berkas initidak disimpan di basisdata.) Tentukan <a class=\"reference internal\" href=\"/id/6.0/ref/settings/#std-setting-MEDIA_URL\"><code class=\"xref std std-setting docutils literal notranslate\">MEDIA_URL</code></a> sebagai URL dasar dari direktori. Pastikan bahwa direktori ini dapat ditulis oleh akun pengguna peladen  jaringan.</p></li>\n<li><p>Tambah <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> ke model anda, menentukan pilihan <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> untuk menentukan subdirectori dari <a class=\"reference internal\" href=\"/id/6.0/ref/settings/#std-setting-MEDIA_ROOT\"><code class=\"xref std std-setting docutils literal notranslate\">MEDIA_ROOT</code></a> untuk digunakan pada berkas-berkas terunggah.</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=\"/id/6.0/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=\"/id/6.0/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\n<code class=\"docutils literal notranslate\">'%Y/%m/%d'</code> part 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=\"(di Python v3.14)\"><code class=\"xref py py-func docutils literal notranslate\">strftime()</code></a>\nformatting; <code class=\"docutils literal notranslate\">'%Y'</code> is the four-digit year, <code class=\"docutils literal notranslate\">'%m'</code> is the two-digit month\nand <code class=\"docutils literal notranslate\">'%d'</code> is the two-digit day. If you upload a file on Jan. 15, 2007, it\nwill be saved in the 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=\"/id/6.0/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=\"/id/6.0/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=\"/id/6.0/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=\"/id/6.0/topics/files/\"><span class=\"doc\">Mengelola berkas</span></a>\ntopic guide.</p>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">Catatan</p>\n<p>Berkas disimpan sebagai bagian dari menyimpan model dalam basisdata, jadi berkas nama sebenarnya digunakan pada cakram tidak dapat bergantung setelah model disimpan.</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=\"/id/6.0/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=\"/id/6.0/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> dan <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>Ketika anda mengakses <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> pada model, anda diberikan sebah contoh dari <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> sebagai sebuah proxy untuk mengakses berkas pokok.</p>\n<p>The API of <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> mirrors that of <a class=\"reference internal\" href=\"/id/6.0/ref/files/file/#django.core.files.File\" title=\"django.core.files.File\"><code class=\"xref py py-class docutils literal notranslate\">File</code></a>,\nwith one key difference: <em>The object wrapped by the class is not necessarily a\nwrapper around Python's built-in file object.</em> Instead, it is a wrapper around\nthe result of the\n<a class=\"reference internal\" href=\"/id/6.0/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> method, which\nmay be a <a class=\"reference internal\" href=\"/id/6.0/ref/files/file/#django.core.files.File\" title=\"django.core.files.File\"><code class=\"xref py py-class docutils literal notranslate\">File</code></a> object, or it may be a custom\nstorage's implementation of the <a class=\"reference internal\" href=\"/id/6.0/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>In addition to the API inherited from <a class=\"reference internal\" href=\"/id/6.0/ref/files/file/#django.core.files.File\" title=\"django.core.files.File\"><code class=\"xref py py-class docutils literal notranslate\">File</code></a> such as\n<code class=\"docutils literal notranslate\">read()</code> and <code class=\"docutils literal notranslate\">write()</code>, <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> includes several methods that\ncan be used to interact with the underlying file:</p>\n<aside class=\"admonition admonition-warning\" role=\"note\">\n<p class=\"admonition-title\">Peringatan</p>\n<p>Dua metode dari kelas ini, <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> dan <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>, awalan pada menyimpan obyek model dari <code class=\"docutils literal notranslate\">FieldFile</code> terkait dalam basisdata.</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>Nama dari berkas termasuk jalur relatif dari akar dari <a class=\"reference internal\" href=\"/id/6.0/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> dari <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> terkait.</p>\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.fields.files.FieldFile.path\">\n<span class=\"sig-prename descclassname\">FieldFile.</span><span class=\"sig-name descname\">path</span><a class=\"heading-anchor\" href=\"#django.db.models.fields.files.FieldFile.path\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>A read-only property to access the file's local filesystem path by calling the\n<a class=\"reference internal\" href=\"/id/6.0/ref/files/storage/#django.core.files.storage.Storage.path\" title=\"django.core.files.storage.Storage.path\"><code class=\"xref py py-meth docutils literal notranslate\">path()</code></a> method of the underlying\n<a class=\"reference internal\" href=\"/id/6.0/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<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>Hasil dari metode pokok <a class=\"reference internal\" href=\"/id/6.0/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 read-only property to access the file's relative URL by calling the\n<a class=\"reference internal\" href=\"/id/6.0/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 underlying\n<a class=\"reference internal\" href=\"/id/6.0/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<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>Opens or reopens the file associated with this instance in the specified\n<code class=\"docutils literal notranslate\">mode</code>. Unlike the standard Python <code class=\"docutils literal notranslate\">open()</code> method, it doesn't return a\nfile descriptor.</p>\n<p>Since the underlying file is opened implicitly when accessing it, it may be\nunnecessary to call this method except to reset the pointer to the underlying\nfile or to change the <code class=\"docutils literal notranslate\">mode</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>Berperilaku seperti metode <code class=\"docutils literal notranslate\">file.close()</code> Python standar dan menutup berkas berkaitan dengan contoh ini.</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>This method takes a filename and file contents and passes them to the storage\nclass for the field, then associates the stored file with the model field.\nIf you want to manually associate file data with\n<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 on your model, the <code class=\"docutils literal notranslate\">save()</code>\nmethod is used to persist that file data.</p>\n<p>Takes two required arguments: <code class=\"docutils literal notranslate\">name</code> which is the name of the file, and\n<code class=\"docutils literal notranslate\">content</code> which is an object containing the file's contents. The\noptional <code class=\"docutils literal notranslate\">save</code> argument controls whether or not the model instance is\nsaved after the file associated with this field has been altered. Defaults to\n<code class=\"docutils literal notranslate\">True</code>.</p>\n<p>Note that the <code class=\"docutils literal notranslate\">content</code> argument should be an instance of\n<a class=\"reference internal\" href=\"/id/6.0/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>, not Python's built-in file object.\nYou can construct a <a class=\"reference internal\" href=\"/id/6.0/ref/files/file/#django.core.files.File\" title=\"django.core.files.File\"><code class=\"xref py py-class docutils literal notranslate\">File</code></a> from an existing\nPython file object like this:</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\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=\"s2\">&quot;/path/to/hello.world&quot;</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>Atau anda dapat membangun satu dari sebush string Python seperti ini:</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\n\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>Untuk informasi lebih, lihat <a class=\"reference internal\" href=\"/id/6.0/topics/files/\"><span class=\"doc\">Mengelola berkas</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>Deletes the file associated with this instance and clears all attributes on\nthe field. Note: This method will close the file if it happens to be open when\n<code class=\"docutils literal notranslate\">delete()</code> is called.</p>\n<p>The optional <code class=\"docutils literal notranslate\">save</code> argument controls whether or not the model instance is\nsaved after the file associated with this field has been deleted. Defaults to\n<code class=\"docutils literal notranslate\">True</code>.</p>\n<p>Note that when a model is deleted, related files are not deleted. If you need\nto cleanup orphaned files, you'll need to handle it yourself (for instance,\nwith a custom management command that can be run manually or scheduled to run\nperiodically via e.g. 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\">''</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\">allow_files<span class=\"o\">=</span><span class=\"default_value\">True</span></em>, <em class=\"sig-param\">allow_folders<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 <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> whose choices are limited to the filenames in a certain\ndirectory on the filesystem. Has some special arguments, of which the first is\n<strong>required</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>Required. The absolute filesystem path to a directory from which this\n<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> should get its choices. Example: <code class=\"docutils literal notranslate\">&quot;/home/images&quot;</code>.</p>\n<p><code class=\"docutils literal notranslate\">path</code> may also be a callable, such as a function to dynamically set the\npath at runtime. 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\">import</span> <span class=\"nn\">os</span>\n<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\n<span class=\"k\">def</span> <span class=\"nf\">images_path</span><span class=\"p\">():</span>\n    <span class=\"k\">return</span> os<span class=\"o\">.</span>path<span class=\"o\">.</span>join<span class=\"p\">(</span>settings<span class=\"o\">.</span>LOCAL_FILE_DIR<span class=\"p\">,</span> <span class=\"s2\">&quot;images&quot;</span><span class=\"p\">)</span>\n\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    file <span class=\"o\">=</span> models<span class=\"o\">.</span>FilePathField<span class=\"p\">(</span>path<span class=\"o\">=</span>images_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.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>Optional. A regular expression, as a string, that <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>\nwill use to filter filenames. Note that the regex will be applied to the\nbase filename, not the full path. Example: <code class=\"docutils literal notranslate\">&quot;foo.*\\.txt$&quot;</code>, which will\nmatch a file called <code class=\"docutils literal notranslate\">foo23.txt</code> but not <code class=\"docutils literal notranslate\">bar.txt</code> or <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>Optional. Either <code class=\"docutils literal notranslate\">True</code> or <code class=\"docutils literal notranslate\">False</code>. Default is <code class=\"docutils literal notranslate\">False</code>. Specifies\nwhether all subdirectories of <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> should be\nincluded</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>Optional. Either <code class=\"docutils literal notranslate\">True</code> or <code class=\"docutils literal notranslate\">False</code>. Default is <code class=\"docutils literal notranslate\">True</code>. Specifies\nwhether files in the specified location should be included. Either this or\n<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> must be <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>Optional. Either <code class=\"docutils literal notranslate\">True</code> or <code class=\"docutils literal notranslate\">False</code>. Default is <code class=\"docutils literal notranslate\">False</code>. Specifies\nwhether folders in the specified location should be included. Either this\nor <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> must be <code class=\"docutils literal notranslate\">True</code>.</p>\n</dd></dl>\n\n<p>The one potential gotcha is that <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> applies to the\nbase filename, not the full path. So, this 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>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>...will match <code class=\"docutils literal notranslate\">/home/images/foo.png</code> but not <code class=\"docutils literal notranslate\">/home/images/foo/bar.png</code>\nbecause the <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> applies to the base filename\n(<code class=\"docutils literal notranslate\">foo.png</code> and <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> 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>\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>Angka floating-point diwakilkan oleh Python oleh instance <code class=\"docutils literal notranslate\">float</code>.</p>\n<p>Widget formulir awalan untuk bidang ini adalah sebuah <a class=\"reference internal\" href=\"/id/6.0/ref/forms/widgets/#django.forms.NumberInput\" title=\"django.forms.NumberInput\"><code class=\"xref py py-class docutils literal notranslate\">NumberInput</code></a> ketika <a class=\"reference internal\" href=\"/id/6.0/ref/forms/fields/#django.forms.Field.localize\" title=\"django.forms.Field.localize\"><code class=\"xref py py-attr docutils literal notranslate\">localize</code></a> adalah <code class=\"docutils literal notranslate\">False</code> atau <a class=\"reference internal\" href=\"/id/6.0/ref/forms/widgets/#django.forms.TextInput\" title=\"django.forms.TextInput\"><code class=\"xref py py-class docutils literal notranslate\">TextInput</code></a> sebaliknya.</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> vs. <code class=\"docutils literal notranslate\">DecimalField</code></p>\n<p>The <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> class is sometimes mixed up with the\n<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> class. Although they both represent real numbers,\nthey represent those numbers differently. <code class=\"docutils literal notranslate\">FloatField</code> uses Python's\n<code class=\"docutils literal notranslate\">float</code> type internally, while <code class=\"docutils literal notranslate\">DecimalField</code> uses Python's <code class=\"docutils literal notranslate\">Decimal</code>\ntype. For information on the difference between the two, see Python's\ndocumentation for the <a class=\"reference external\" href=\"https://docs.python.org/3/library/decimal.html#module-decimal\" title=\"(di Python v3.14)\"><code class=\"xref py py-mod docutils literal notranslate\">decimal</code></a> module.</p>\n</aside>\n</section>\n<section id=\"generatedfield\">\n<h3><code class=\"docutils literal notranslate\">GeneratedField</code><a class=\"heading-anchor\" href=\"#generatedfield\"><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.GeneratedField\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">GeneratedField</span><span class=\"sig-paren\">(</span><em class=\"sig-param\"><span class=\"keyword-only-separator o\"><abbr title=\"Keyword-only parameters separator (PEP 3102)\">*</abbr></span></em>, <em class=\"sig-param\">expression</em>, <em class=\"sig-param\">output_field</em>, <em class=\"sig-param\">db_persist</em>, <em class=\"sig-param\"><span class=\"o\">**</span>kwargs</em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.db.models.GeneratedField\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>A field that is always computed based on other fields in the model. This field\nis managed and updated by the database itself. Uses the <code class=\"docutils literal notranslate\">GENERATED ALWAYS</code>\nSQL syntax.</p>\n<p>There are two kinds of generated columns: stored and virtual. A stored\ngenerated column is computed when it is written (inserted or updated) and\noccupies storage as if it were a regular column. A virtual generated column\noccupies no storage and is computed when it is read. Thus, a virtual generated\ncolumn is similar to a view and a stored generated column is similar to a\nmaterialized view.</p>\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.GeneratedField.expression\">\n<span class=\"sig-prename descclassname\">GeneratedField.</span><span class=\"sig-name descname\">expression</span><a class=\"heading-anchor\" href=\"#django.db.models.GeneratedField.expression\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>An <a class=\"reference internal\" href=\"/id/6.0/ref/models/expressions/#django.db.models.Expression\" title=\"django.db.models.Expression\"><code class=\"xref py py-class docutils literal notranslate\">Expression</code></a> used by the database to automatically set the field\nvalue each time the model is changed.</p>\n<p>The expressions should be deterministic and only reference fields within\nthe model (in the same database table). Generated fields cannot reference\nother generated fields. Database backends can impose further restrictions.</p>\n</dd></dl>\n\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.GeneratedField.output_field\">\n<span class=\"sig-prename descclassname\">GeneratedField.</span><span class=\"sig-name descname\">output_field</span><a class=\"heading-anchor\" href=\"#django.db.models.GeneratedField.output_field\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>A model field instance to define the field's data type.</p>\n</dd></dl>\n\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.GeneratedField.db_persist\">\n<span class=\"sig-prename descclassname\">GeneratedField.</span><span class=\"sig-name descname\">db_persist</span><a class=\"heading-anchor\" href=\"#django.db.models.GeneratedField.db_persist\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Determines if the database column should occupy storage as if it were a\nreal column. If <code class=\"docutils literal notranslate\">False</code>, the column acts as a virtual column and does\nnot occupy database storage space.</p>\n<p>PostgreSQL only supports persisted columns. Oracle only supports virtual\ncolumns.</p>\n</dd></dl>\n\n<aside class=\"admonition-database-limitations admonition\" role=\"note\">\n<p class=\"admonition-title\">Database limitations</p>\n<p>There are many database-specific restrictions on generated fields that\nDjango doesn't validate and the database may raise an error e.g. PostgreSQL\nrequires functions and operators referenced in a generated column to be\nmarked as <code class=\"docutils literal notranslate\">IMMUTABLE</code>.</p>\n<p>You should always check that <code class=\"docutils literal notranslate\">expression</code> is supported on your database.\nCheck out <a class=\"reference external\" href=\"https://mariadb.com/kb/en/generated-columns/#expression-support\">MariaDB</a>, <a class=\"reference external\" href=\"https://dev.mysql.com/doc/refman/en/create-table-generated-columns.html\">MySQL</a>, <a class=\"reference external\" href=\"https://docs.oracle.com/en/database/oracle/oracle-database/21/sqlrf/CREATE-TABLE.html#GUID-F9CE0CC3-13AE-4744-A43C-EAC7A71AAAB6__BABIIGBD\">Oracle</a>, <a class=\"reference external\" href=\"https://www.postgresql.org/docs/current/ddl-generated-columns.html\">PostgreSQL</a>, or <a class=\"reference external\" href=\"https://www.sqlite.org/gencol.html#limitations\">SQLite</a>\ndocs.</p>\n</aside>\n<aside class=\"version-note version-changed\" data-version=\"6.0\" role=\"note\">\n<p class=\"version-note-title\">Changed in Django 6.0</p><p><code class=\"docutils literal notranslate\">GeneratedField</code>s are now automatically refreshed from the database on\nbackends that support it (SQLite, PostgreSQL, and Oracle) and marked as\ndeferred otherwise.</p>\n</aside>\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>An IPv4 or IPv6 address, in string format (e.g. <code class=\"docutils literal notranslate\">192.0.2.30</code> or\n<code class=\"docutils literal notranslate\">2a02:42fe::4</code>). The default form widget for this field is a\n<a class=\"reference internal\" href=\"/id/6.0/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>Normalisasi alamat IPv6 mengikuti <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> bagian 2.2, termasuk menggunakan bentuk IPv4 disarankan dalam paragraf 3 dari bagian itu, seperti <code class=\"docutils literal notranslate\">::ffff:192.0.2.0</code>. Sebagai contoh, <code class=\"docutils literal notranslate\">2001:0::0:01</code> akan dinormalkan menjadi <code class=\"docutils literal notranslate\">2001::1</code>, dan <code class=\"docutils literal notranslate\">::ffff:0a0a:0a0a</code> menjadi <code class=\"docutils literal notranslate\">::ffff:10.10.10.10</code>. Semau karakter dirubah menjadi huruf kecil.</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>Limits valid inputs to the specified protocol.\nAccepted values are <code class=\"docutils literal notranslate\">'both'</code> (default), <code class=\"docutils literal notranslate\">'IPv4'</code>\nor <code class=\"docutils literal notranslate\">'IPv6'</code>. Matching is case insensitive.</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>Unpacks IPv4 mapped addresses like <code class=\"docutils literal notranslate\">::ffff:192.0.2.1</code>.\nIf this option is enabled that address would be unpacked to\n<code class=\"docutils literal notranslate\">192.0.2.1</code>. Default is disabled. Can only be used\nwhen <code class=\"docutils literal notranslate\">protocol</code> is set to <code class=\"docutils literal notranslate\">'both'</code>.</p>\n</dd></dl>\n\n<p>Jika anda mengizinkan nilai kosong, anda harus mengizinkan nilai null karena nilai kosong disimpan sebagai null.</p>\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>Inherits all attributes and methods from <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>, but also\nvalidates that the uploaded object is a valid image.</p>\n<p>In addition to the special attributes that are available for\n<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>, an <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> also has <code class=\"docutils literal notranslate\">height</code> and <code class=\"docutils literal notranslate\">width</code>\nattributes.</p>\n<p>To facilitate querying on those attributes, <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> has the\nfollowing optional arguments:</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>Name of a model field which is auto-populated with the height of the image\neach time an image object is set.</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>Name of a model field which is auto-populated with the width of the image\neach time an image object is set.</p>\n</dd></dl>\n\n<p>Requires the <a class=\"extlink-pypi reference external\" href=\"https://pypi.org/project/pillow/\">pillow</a> library.</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> 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<p>Widget formulir awalan untuk bidang ini adalah <a class=\"reference internal\" href=\"/id/6.0/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>An integer. Values are only allowed between certain (database-dependent)\npoints. Values from <code class=\"docutils literal notranslate\">-2147483648</code> to <code class=\"docutils literal notranslate\">2147483647</code> are compatible in all\ndatabases supported by Django.</p>\n<p>Itu menggunakan <a class=\"reference internal\" href=\"/id/6.0/ref/validators/#django.core.validators.MinValueValidator\" title=\"django.core.validators.MinValueValidator\"><code class=\"xref py py-class docutils literal notranslate\">MinValueValidator</code></a> dan <a class=\"reference internal\" href=\"/id/6.0/ref/validators/#django.core.validators.MaxValueValidator\" title=\"django.core.validators.MaxValueValidator\"><code class=\"xref py py-class docutils literal notranslate\">MaxValueValidator</code></a> untuk mensahkan masukan berdasarkan pada nilai yang didukung basisdata awalan.</p>\n<p>Widget formulir awalan untuk bidang ini adalah sebuah <a class=\"reference internal\" href=\"/id/6.0/ref/forms/widgets/#django.forms.NumberInput\" title=\"django.forms.NumberInput\"><code class=\"xref py py-class docutils literal notranslate\">NumberInput</code></a> ketika <a class=\"reference internal\" href=\"/id/6.0/ref/forms/fields/#django.forms.Field.localize\" title=\"django.forms.Field.localize\"><code class=\"xref py py-attr docutils literal notranslate\">localize</code></a> adalah <code class=\"docutils literal notranslate\">False</code> atau <a class=\"reference internal\" href=\"/id/6.0/ref/forms/widgets/#django.forms.TextInput\" title=\"django.forms.TextInput\"><code class=\"xref py py-class docutils literal notranslate\">TextInput</code></a> sebaliknya.</p>\n</section>\n<section id=\"jsonfield\">\n<h3><code class=\"docutils literal notranslate\">JSONField</code><a class=\"heading-anchor\" href=\"#jsonfield\"><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.JSONField\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">JSONField</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">encoder<span class=\"o\">=</span><span class=\"default_value\">None</span></em>, <em class=\"sig-param\">decoder<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.JSONField\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>Sebuah bidang untuk menyimpan data tersandi JSON. Dalam Python data diwakili dalam bentuk asli Python nya: dictionary, string, angka, booelan dan <code class=\"docutils literal notranslate\">None</code>.</p>\n<p><code class=\"docutils literal notranslate\">JSONField</code> is supported on MariaDB, MySQL, Oracle, PostgreSQL, and SQLite\n(with the <a class=\"reference internal\" href=\"/id/6.0/ref/databases/#sqlite-json1\"><span class=\"std std-ref\">JSON1 extension enabled</span></a>).</p>\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.JSONField.encoder\">\n<span class=\"sig-prename descclassname\">JSONField.</span><span class=\"sig-name descname\">encoder</span><a class=\"heading-anchor\" href=\"#django.db.models.JSONField.encoder\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>An optional <a class=\"reference external\" href=\"https://docs.python.org/3/library/json.html#json.JSONEncoder\" title=\"(di Python v3.14)\"><code class=\"xref py py-class docutils literal notranslate\">json.JSONEncoder</code></a> subclass to serialize data types\nnot supported by the standard JSON serializer (e.g. <code class=\"docutils literal notranslate\">datetime.datetime</code>\nor <a class=\"reference external\" href=\"https://docs.python.org/3/library/uuid.html#uuid.UUID\" title=\"(di Python v3.14)\"><code class=\"xref py py-class docutils literal notranslate\">UUID</code></a>). For example, you can use the\n<a class=\"reference internal\" href=\"/id/6.0/topics/serialization/#django.core.serializers.json.DjangoJSONEncoder\" title=\"django.core.serializers.json.DjangoJSONEncoder\"><code class=\"xref py py-class docutils literal notranslate\">DjangoJSONEncoder</code></a> class.</p>\n<p>Awalan untuk <code class=\"docutils literal notranslate\">json.JSONEncoder</code>.</p>\n</dd></dl>\n\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.JSONField.decoder\">\n<span class=\"sig-prename descclassname\">JSONField.</span><span class=\"sig-name descname\">decoder</span><a class=\"heading-anchor\" href=\"#django.db.models.JSONField.decoder\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>An optional <a class=\"reference external\" href=\"https://docs.python.org/3/library/json.html#json.JSONDecoder\" title=\"(di Python v3.14)\"><code class=\"xref py py-class docutils literal notranslate\">json.JSONDecoder</code></a> subclass to deserialize the value\nretrieved from the database. The value will be in the format chosen by the\ncustom encoder (most often a string). Your deserialization may need to\naccount for the fact that you can't be certain of the input type. For\nexample, you run the risk of returning a <code class=\"docutils literal notranslate\">datetime</code> that was actually a\nstring that just happened to be in the same format chosen for\n<code class=\"docutils literal notranslate\">datetime</code>s.</p>\n<p>Awalan untuk <code class=\"docutils literal notranslate\">json.JSONDecoder</code>.</p>\n</dd></dl>\n\n<p>To query <code class=\"docutils literal notranslate\">JSONField</code> in the database, see <a class=\"reference internal\" href=\"/id/6.0/topics/db/queries/#querying-jsonfield\"><span class=\"std std-ref\">Meminta JSONField</span></a>.</p>\n<aside class=\"admonition-default-value admonition\" role=\"note\">\n<p class=\"admonition-title\">Default value</p>\n<p>If you give the field 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>, ensure\nit's a callable such as the <a class=\"reference external\" href=\"https://docs.python.org/3/library/stdtypes.html#dict\" title=\"(di Python v3.14)\"><code class=\"xref py py-class docutils literal notranslate\">dict</code></a> class or a function that\nreturns a fresh object each time. Incorrectly using a mutable object like\n<code class=\"docutils literal notranslate\">default={}</code> or <code class=\"docutils literal notranslate\">default=[]</code> creates a mutable default that is shared\nbetween all instances.</p>\n</aside>\n<aside class=\"admonition-indexing admonition\" role=\"note\">\n<p class=\"admonition-title\">Indexing</p>\n<p><a class=\"reference internal\" href=\"/id/6.0/ref/models/indexes/#django.db.models.Index\" title=\"django.db.models.Index\"><code class=\"xref py py-class docutils literal notranslate\">Index</code></a> and <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> both create a\nB-tree index, which isn't particularly helpful when querying <code class=\"docutils literal notranslate\">JSONField</code>.\nOn PostgreSQL only, you can use\n<a class=\"reference internal\" href=\"/id/6.0/ref/contrib/postgres/indexes/#django.contrib.postgres.indexes.GinIndex\" title=\"django.contrib.postgres.indexes.GinIndex\"><code class=\"xref py py-class docutils literal notranslate\">GinIndex</code></a> that is better suited.</p>\n</aside>\n<aside class=\"admonition-postgresql-users admonition\" role=\"note\">\n<p class=\"admonition-title\">Pengguna PostgreSQL</p>\n<p>PostgreSQL mempunyai dua jenis data berdasarkan JSON asli: <code class=\"docutils literal notranslate\">json</code> dan <code class=\"docutils literal notranslate\">jsonb</code>. Perbedaan utama diantara mereka adalah bagaimana mereka disimpan dan bagaimana mereka dapat diminta. Bidang <code class=\"docutils literal notranslate\">json</code> PostgreSQL disimpan sebagai perwakilan string asli dari JSON dan harus disandikan dengan cepat ketika permintaan berdasarkan pada kunci-kunci. Bidang <code class=\"docutils literal notranslate\">jsonb</code> disimpan berdasarkan pada struktur sebenarnya dari JSON yang mengizinkan pengindeksan. Pertukaran adalah tambahan biaya kecil pada menulis ke bidang <code class=\"docutils literal notranslate\">jsonb</code> field. <code class=\"docutils literal notranslate\">JSONField</code> menggunakan <code class=\"docutils literal notranslate\">jsonb</code>.</p>\n</aside>\n<aside class=\"admonition-oracle-users admonition\" role=\"note\">\n<p class=\"admonition-title\">Pengguna Oracle</p>\n<p>Oracle Database does not support storing JSON scalar values. Only JSON\nobjects and arrays (represented in Python using <a class=\"reference external\" href=\"https://docs.python.org/3/library/stdtypes.html#dict\" title=\"(di Python v3.14)\"><code class=\"xref py py-class docutils literal notranslate\">dict</code></a> and\n<a class=\"reference external\" href=\"https://docs.python.org/3/library/stdtypes.html#list\" title=\"(di Python v3.14)\"><code class=\"xref py py-class docutils literal notranslate\">list</code></a>) are supported.</p>\n</aside>\n</section>\n<section id=\"positivebigintegerfield\">\n<h3><code class=\"docutils literal notranslate\">PositiveBigIntegerField</code><a class=\"heading-anchor\" href=\"#positivebigintegerfield\"><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.PositiveBigIntegerField\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">PositiveBigIntegerField</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.PositiveBigIntegerField\"><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 <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>, but only allows values under a certain\n(database-dependent) point. Values from <code class=\"docutils literal notranslate\">0</code> to <code class=\"docutils literal notranslate\">9223372036854775807</code> are\ncompatible in all databases supported by Django.</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>Like an <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>, but must be either positive or zero (<code class=\"docutils literal notranslate\">0</code>).\nValues are only allowed under a certain (database-dependent) point. Values from\n<code class=\"docutils literal notranslate\">0</code> to <code class=\"docutils literal notranslate\">2147483647</code> are compatible in all databases supported by Django.\nThe value <code class=\"docutils literal notranslate\">0</code> is accepted for backward compatibility reasons.</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>Like a <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>, but only allows values under a certain\n(database-dependent) point. Values from <code class=\"docutils literal notranslate\">0</code> to <code class=\"docutils literal notranslate\">32767</code> are compatible in\nall databases supported by Django.</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=\"/id/6.0/glossary/#term-slug\"><span class=\"xref std std-term\">Slug</span></a> is a newspaper term. A slug is a short label for something,\ncontaining only letters, numbers, underscores or hyphens. They're generally\nused in URLs.</p>\n<p>Like a CharField, you can specify <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> (read the note\nabout database portability and <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> in that section,\ntoo). If <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> is not specified, Django will use a\ndefault length of 50.</p>\n<p>menunjuk pengaturan <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> ke <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=\"/id/6.0/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<p>Itu menggunakan <a class=\"reference internal\" href=\"/id/6.0/ref/validators/#django.core.validators.validate_slug\" title=\"django.core.validators.validate_slug\"><code class=\"xref py py-class docutils literal notranslate\">validate_slug</code></a> atau <a class=\"reference internal\" href=\"/id/6.0/ref/validators/#django.core.validators.validate_unicode_slug\" title=\"django.core.validators.validate_unicode_slug\"><code class=\"xref py py-class docutils literal notranslate\">validate_unicode_slug</code></a> for validation.</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><p>Jika <code class=\"docutils literal notranslate\">True</code>, bidang menerima huruf Unicode ebagai tambahan pada huruf ASCII. Awalan menjadi <code class=\"docutils literal notranslate\">False</code>.</p>\n</dd></dl>\n\n</section>\n<section id=\"smallautofield\">\n<h3><code class=\"docutils literal notranslate\">SmallAutoField</code><a class=\"heading-anchor\" href=\"#smallautofield\"><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.SmallAutoField\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">SmallAutoField</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.SmallAutoField\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>Like 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>, but only allows values under a certain\n(database-dependent) limit. Values from <code class=\"docutils literal notranslate\">1</code> to <code class=\"docutils literal notranslate\">32767</code> are compatible in\nall databases supported by Django.</p>\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>Like an <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>, but only allows values under a certain\n(database-dependent) point. Values from <code class=\"docutils literal notranslate\">-32768</code> to <code class=\"docutils literal notranslate\">32767</code> are compatible\nin all databases supported by Django.</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 large text field. The default form widget for this field is a\n<a class=\"reference internal\" href=\"/id/6.0/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>Jika anda menentukan atribut <code class=\"docutils literal notranslate\">max_length</code>, itu akan dipantulkan di widget <a class=\"reference internal\" href=\"/id/6.0/ref/forms/widgets/#django.forms.Textarea\" title=\"django.forms.Textarea\"><code class=\"xref py py-class docutils literal notranslate\">Textarea</code></a> dari bidang formulir dibangkitkan-otomatis. Bagaimanapun itu tidak dipaksa pada model atau tingkatan basisdata. Gunakan <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> untuk itu.</p>\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.TextField.db_collation\">\n<span class=\"sig-prename descclassname\">TextField.</span><span class=\"sig-name descname\">db_collation</span><a class=\"heading-anchor\" href=\"#django.db.models.TextField.db_collation\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Optional. The database collation name of the field.</p>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">Catatan</p>\n<p>Collation names are not standardized. As such, this will not be\nportable across multiple database backends.</p>\n</aside>\n<aside class=\"admonition-oracle admonition\" role=\"note\">\n<p class=\"admonition-title\">Oracle</p>\n<p>Oracle does not support collations for a <code class=\"docutils literal notranslate\">TextField</code>.</p>\n</aside>\n</dd></dl>\n\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>A time, represented in Python by a <code class=\"docutils literal notranslate\">datetime.time</code> instance. Accepts the same\nauto-population options as <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>The default form widget for this field is a <a class=\"reference internal\" href=\"/id/6.0/ref/forms/widgets/#django.forms.TimeInput\" title=\"django.forms.TimeInput\"><code class=\"xref py py-class docutils literal notranslate\">TimeInput</code></a>.\nThe admin adds some JavaScript shortcuts.</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>Sebuah <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> untuk URL, disahkan oleh <a class=\"reference internal\" href=\"/id/6.0/ref/validators/#django.core.validators.URLValidator\" title=\"django.core.validators.URLValidator\"><code class=\"xref py py-class docutils literal notranslate\">URLValidator</code></a>.</p>\n<p>The default form widget for this field is a <a class=\"reference internal\" href=\"/id/6.0/ref/forms/widgets/#django.forms.URLInput\" title=\"django.forms.URLInput\"><code class=\"xref py py-class docutils literal notranslate\">URLInput</code></a>.</p>\n<p>Seperti semua <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> subclasses, <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> mengambil pilihan argumen <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>. Jika anda tidak menentukan <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>, sebuah awalan 200 digunakan.</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>A field for storing universally unique identifiers. Uses Python's\n<a class=\"reference external\" href=\"https://docs.python.org/3/library/uuid.html#uuid.UUID\" title=\"(di Python v3.14)\"><code class=\"xref py py-class docutils literal notranslate\">UUID</code></a> class. When used on PostgreSQL and MariaDB 10.7+,\nthis stores in a <code class=\"docutils literal notranslate\">uuid</code> datatype, otherwise in a <code class=\"docutils literal notranslate\">char(32)</code>.</p>\n<p>Universally unique identifiers are a good alternative to <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> for\n<a class=\"reference internal\" href=\"#django.db.models.Field.primary_key\" title=\"django.db.models.Field.primary_key\"><code class=\"xref py py-attr docutils literal notranslate\">primary_key</code></a>. The database will not generate the UUID for you, so\nit is recommended to use <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\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>Catata bahwa sebuah callable (dengan tanda kurung dihapus) dilewatkan pada <code class=\"docutils literal notranslate\">default</code>, bukan sebuah instance dari <code class=\"docutils literal notranslate\">UUID</code>.</p>\n<aside class=\"admonition-lookups-on-postgresql-and-mariadb-10-7 admonition\" role=\"note\">\n<p class=\"admonition-title\">Lookups on PostgreSQL and MariaDB 10.7+</p>\n<p>Using <a class=\"reference internal\" href=\"/id/6.0/ref/models/querysets/#std-fieldlookup-iexact\"><code class=\"xref std std-lookup docutils literal notranslate\">iexact</code></a>, <a class=\"reference internal\" href=\"/id/6.0/ref/models/querysets/#std-fieldlookup-contains\"><code class=\"xref std std-lookup docutils literal notranslate\">contains</code></a>, <a class=\"reference internal\" href=\"/id/6.0/ref/models/querysets/#std-fieldlookup-icontains\"><code class=\"xref std std-lookup docutils literal notranslate\">icontains</code></a>,\n<a class=\"reference internal\" href=\"/id/6.0/ref/models/querysets/#std-fieldlookup-startswith\"><code class=\"xref std std-lookup docutils literal notranslate\">startswith</code></a>, <a class=\"reference internal\" href=\"/id/6.0/ref/models/querysets/#std-fieldlookup-istartswith\"><code class=\"xref std std-lookup docutils literal notranslate\">istartswith</code></a>, <a class=\"reference internal\" href=\"/id/6.0/ref/models/querysets/#std-fieldlookup-endswith\"><code class=\"xref std std-lookup docutils literal notranslate\">endswith</code></a>, or\n<a class=\"reference internal\" href=\"/id/6.0/ref/models/querysets/#std-fieldlookup-iendswith\"><code class=\"xref std std-lookup docutils literal notranslate\">iendswith</code></a> lookups on PostgreSQL don't work for values without\nhyphens, because PostgreSQL and MariaDB 10.7+ store them in a hyphenated\nuuid datatype type.</p>\n</aside>\n</section>\n</section>\n<section id=\"module-django.db.models.fields.related\">\n<span id=\"id1\"></span><span id=\"relationship-fields\"></span><h2>Bidang hubungan<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 juga menentukan kumpulan bidang yang mewakili hubungan.</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\">to</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>A many-to-one relationship. Requires two positional arguments: the class to\nwhich the model is related and the <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> option:</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\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    name <span class=\"o\">=</span> models<span class=\"o\">.</span>TextField<span class=\"p\">()</span>\n\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>Manufacturer<span class=\"p\">,</span> on_delete<span class=\"o\">=</span>models<span class=\"o\">.</span>CASCADE<span class=\"p\">)</span>\n</code></pre></div>\n<p>The first positional argument can be either a concrete model class or a\n<a class=\"reference internal\" href=\"#lazy-relationships\"><span class=\"std std-ref\">lazy reference</span></a> to a model class.\n<a class=\"reference internal\" href=\"#recursive-relationships\"><span class=\"std std-ref\">Recursive relationships</span></a>, where a model has a\nrelationship with itself, are also supported.</p>\n<p>See <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\">ForeignKey.on_delete</code></a> for details on the second positional\nargument.</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>Perwakilan Basisdata<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>Penjelasan<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> menerima argumen lain yang menentukan rincian dari bagaimana hubungan bekerja.</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<p><code class=\"docutils literal notranslate\">on_delete</code> doesn't create an SQL constraint in the database. Support for\ndatabase-level cascade options <a class=\"extlink-ticket reference external\" href=\"https://code.djangoproject.com/ticket/21961\">may be implemented later</a>.</p>\n</dd></dl>\n\n<p>Nilai-nilai kemungkinan untuk <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> ditemukan dalam <a class=\"reference internal\" href=\"/id/6.0/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 <code class=\"docutils literal notranslate\">ON\nDELETE CASCADE</code> and also deletes the object containing 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>.</p>\n<p><a class=\"reference internal\" href=\"/id/6.0/ref/models/instances/#django.db.models.Model.delete\" title=\"django.db.models.Model.delete\"><code class=\"xref py py-meth docutils literal notranslate\">Model.delete()</code></a> isn't called on related models, but the\n<a class=\"reference internal\" href=\"/id/6.0/ref/signals/#django.db.models.signals.pre_delete\" title=\"django.db.models.signals.pre_delete\"><code class=\"xref py py-data docutils literal notranslate\">pre_delete</code></a> and\n<a class=\"reference internal\" href=\"/id/6.0/ref/signals/#django.db.models.signals.post_delete\" title=\"django.db.models.signals.post_delete\"><code class=\"xref py py-data docutils literal notranslate\">post_delete</code></a> signals are sent for all\ndeleted objects.</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=\"/id/6.0/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=\"/id/6.0/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.RESTRICT\">\n<span class=\"sig-name descname\">RESTRICT</span><a class=\"heading-anchor\" href=\"#django.db.models.RESTRICT\"><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=\"/id/6.0/ref/exceptions/#django.db.models.RestrictedError\" title=\"django.db.models.RestrictedError\"><code class=\"xref py py-exc docutils literal notranslate\">RestrictedError</code></a> (a subclass of\n<a class=\"reference internal\" href=\"/id/6.0/ref/exceptions/#django.db.IntegrityError\" title=\"django.db.IntegrityError\"><code class=\"xref py py-exc docutils literal notranslate\">django.db.IntegrityError</code></a>). Unlike <a class=\"reference internal\" href=\"#django.db.models.PROTECT\" title=\"django.db.models.PROTECT\"><code class=\"xref py py-attr docutils literal notranslate\">PROTECT</code></a>, deletion of the\nreferenced object is allowed if it also references a different object\nthat is being deleted in the same operation, but via a <a class=\"reference internal\" href=\"#django.db.models.CASCADE\" title=\"django.db.models.CASCADE\"><code class=\"xref py py-attr docutils literal notranslate\">CASCADE</code></a>\nrelationship.</p>\n<p>Pertimbangkan kumpulan model ini:</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\">Artist</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\">10</span><span class=\"p\">)</span>\n\n\n<span class=\"k\">class</span> <span class=\"nc\">Album</span><span class=\"p\">(</span>models<span class=\"o\">.</span>Model<span class=\"p\">):</span>\n    artist <span class=\"o\">=</span> models<span class=\"o\">.</span>ForeignKey<span class=\"p\">(</span>Artist<span class=\"p\">,</span> on_delete<span class=\"o\">=</span>models<span class=\"o\">.</span>CASCADE<span class=\"p\">)</span>\n\n\n<span class=\"k\">class</span> <span class=\"nc\">Song</span><span class=\"p\">(</span>models<span class=\"o\">.</span>Model<span class=\"p\">):</span>\n    artist <span class=\"o\">=</span> models<span class=\"o\">.</span>ForeignKey<span class=\"p\">(</span>Artist<span class=\"p\">,</span> on_delete<span class=\"o\">=</span>models<span class=\"o\">.</span>CASCADE<span class=\"p\">)</span>\n    album <span class=\"o\">=</span> models<span class=\"o\">.</span>ForeignKey<span class=\"p\">(</span>Album<span class=\"p\">,</span> on_delete<span class=\"o\">=</span>models<span class=\"o\">.</span>RESTRICT<span class=\"p\">)</span>\n</code></pre></div>\n<p><code class=\"docutils literal notranslate\">Artist</code> can be deleted even if that implies deleting an <code class=\"docutils literal notranslate\">Album</code>\nwhich is referenced by a <code class=\"docutils literal notranslate\">Song</code>, because <code class=\"docutils literal notranslate\">Song</code> also references\n<code class=\"docutils literal notranslate\">Artist</code> itself through a cascading relationship. For example:</p>\n<div class=\"code-block\" data-language=\"pycon\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python console</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=\"Python console code\"><code><span class=\"gp\">&gt;&gt;&gt; </span>artist_one <span class=\"o\">=</span> Artist<span class=\"o\">.</span>objects<span class=\"o\">.</span>create<span class=\"p\">(</span>name<span class=\"o\">=</span><span class=\"s2\">&quot;artist one&quot;</span><span class=\"p\">)</span>\n<span class=\"gp\">&gt;&gt;&gt; </span>artist_two <span class=\"o\">=</span> Artist<span class=\"o\">.</span>objects<span class=\"o\">.</span>create<span class=\"p\">(</span>name<span class=\"o\">=</span><span class=\"s2\">&quot;artist two&quot;</span><span class=\"p\">)</span>\n<span class=\"gp\">&gt;&gt;&gt; </span>album_one <span class=\"o\">=</span> Album<span class=\"o\">.</span>objects<span class=\"o\">.</span>create<span class=\"p\">(</span>artist<span class=\"o\">=</span>artist_one<span class=\"p\">)</span>\n<span class=\"gp\">&gt;&gt;&gt; </span>album_two <span class=\"o\">=</span> Album<span class=\"o\">.</span>objects<span class=\"o\">.</span>create<span class=\"p\">(</span>artist<span class=\"o\">=</span>artist_two<span class=\"p\">)</span>\n<span class=\"gp\">&gt;&gt;&gt; </span>song_one <span class=\"o\">=</span> Song<span class=\"o\">.</span>objects<span class=\"o\">.</span>create<span class=\"p\">(</span>artist<span class=\"o\">=</span>artist_one<span class=\"p\">,</span> album<span class=\"o\">=</span>album_one<span class=\"p\">)</span>\n<span class=\"gp\">&gt;&gt;&gt; </span>song_two <span class=\"o\">=</span> Song<span class=\"o\">.</span>objects<span class=\"o\">.</span>create<span class=\"p\">(</span>artist<span class=\"o\">=</span>artist_one<span class=\"p\">,</span> album<span class=\"o\">=</span>album_two<span class=\"p\">)</span>\n<span class=\"gp\">&gt;&gt;&gt; </span>album_one<span class=\"o\">.</span>delete<span class=\"p\">()</span>\n<span class=\"go\"># Raises RestrictedError.</span>\n<span class=\"gp\">&gt;&gt;&gt; </span>artist_two<span class=\"o\">.</span>delete<span class=\"p\">()</span>\n<span class=\"go\"># Raises RestrictedError.</span>\n<span class=\"gp\">&gt;&gt;&gt; </span>artist_one<span class=\"o\">.</span>delete<span class=\"p\">()</span>\n<span class=\"go\">(4, {&#39;Song&#39;: 2, &#39;Album&#39;: 1, &#39;Artist&#39;: 1})</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.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>Setel <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; ini hanya memungkinkan jika <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> adalah <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>Setel <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> ke nilai awalannya; sebuah awalan untuk <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> harus disetel.</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 <code class=\"docutils literal notranslate\">models.py</code> 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\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=\"s2\">&quot;deleted&quot;</span><span class=\"p\">)[</span><span class=\"mi\">0</span><span class=\"p\">]</span>\n\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=\"/id/6.0/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=\"/id/6.0/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=\"/id/6.0/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>Sebagai contoh:</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=\"s2\">&quot;is_staff&quot;</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\">User</code>\ninstances that have <code class=\"docutils literal notranslate\">is_staff=True</code>. This may be helpful in the Django\nadmin.</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=\"s2\">&quot;pub_date__lte&quot;</span><span class=\"p\">:</span> datetime<span class=\"o\">.</span>date<span class=\"o\">.</span>today<span class=\"p\">()}</span>\n\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=\"/id/6.0/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=\"/id/6.0/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=\"/id/6.0/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\">Catatan</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=\"/id/6.0/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=\"/id/6.0/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=\"/id/6.0/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=\"s2\">&quot;+&quot;</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=\"/id/6.0/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\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=\"/id/6.0/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>Anda mempunyai warisan data yang tidak sah.</p></li>\n<li><p>Anda sedang memecah basisdata anda.</p></li>\n</ul>\n<p>Jika ini disetel menjadi <code class=\"docutils literal notranslate\">False</code>, mengakses obyek terkait yang tidak ada akan memunculkan pengecualian <code class=\"docutils literal notranslate\">DoesNotExist</code> nya.</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 toward 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> means that the migrations made\nwith 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> will always reference the exact model you\nspecify (so it will fail hard if the user tries to run with a <code class=\"docutils literal notranslate\">User</code>\nmodel you don't support, for example).</p>\n<p>Jika dalam keraguan, tinggalkan itu ke awalan menjadi <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\">to</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=\"/id/6.0/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=\"id2\">\n<h4>Perwakilan Basisdata<a class=\"heading-anchor\" href=\"#id2\"><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 and a uniqueness hash\nwill be used, e.g. <code class=\"docutils literal notranslate\">author_books_9cdf</code>. You can manually provide the name of\nthe 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=\"id3\"></span><h4>Penjelasan<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>Sama seperti <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>Sama seperti <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>Sama seperti <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</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>Hanya digunakan dalam pengertian dari ManyToManyFields pada diri sendiri. pertimbangkan model berikut:</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\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>,\nset <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\nDjango to add 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 <code class=\"docutils literal notranslate\">through</code> model can be specified using either the model class\ndirectly or a <a class=\"reference internal\" href=\"#lazy-relationships\"><span class=\"std std-ref\">lazy reference</span></a> to the model\nclass.</p>\n<p>Penggunaan paling umum dari pilihan ini adalah ketika anda ingin mengkaitkan <a class=\"reference internal\" href=\"/id/6.0/topics/db/models/#intermediary-manytomany\"><span class=\"std std-ref\">extra data with a many-to-many relationship</span></a>.</p>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">Catatan</p>\n<p>Recursive relationships using an intermediary model can't determine the\nreverse accessors names, as they would be the same. You need to set a\n<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> to at least one of them. If you'd\nprefer Django not to create a backwards relation, set <code class=\"docutils literal notranslate\">related_name</code>\nto <code class=\"docutils literal notranslate\">'+'</code>.</p>\n</aside>\n<aside class=\"admonition-foreign-key-order-in-intermediary-models admonition\" role=\"note\">\n<p class=\"admonition-title\">Foreign key order in intermediary models</p>\n<p>When defining an asymmetric many-to-many relationship from a model to\nitself using an intermediary model without defining\n<a class=\"reference internal\" href=\"#django.db.models.ManyToManyField.through_fields\" title=\"django.db.models.ManyToManyField.through_fields\"><code class=\"xref py py-attr docutils literal notranslate\">through_fields</code></a>, the first foreign key in the intermediary model\nwill be treated as representing the source side of the\n<code class=\"docutils literal notranslate\">ManyToManyField</code>, and the second as the target side. 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=\"kn\">from</span> <span class=\"nn\">django.db</span> <span class=\"kn\">import</span> models\n\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    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    clients <span class=\"o\">=</span> models<span class=\"o\">.</span>ManyToManyField<span class=\"p\">(</span>\n        <span class=\"s2\">&quot;self&quot;</span><span class=\"p\">,</span> symmetrical<span class=\"o\">=</span><span class=\"kc\">False</span><span class=\"p\">,</span> related_name<span class=\"o\">=</span><span class=\"s2\">&quot;suppliers&quot;</span><span class=\"p\">,</span> through<span class=\"o\">=</span><span class=\"s2\">&quot;Supply&quot;</span>\n    <span class=\"p\">)</span>\n\n\n<span class=\"k\">class</span> <span class=\"nc\">Supply</span><span class=\"p\">(</span>models<span class=\"o\">.</span>Model<span class=\"p\">):</span>\n    supplier <span class=\"o\">=</span> models<span class=\"o\">.</span>ForeignKey<span class=\"p\">(</span>\n        Manufacturer<span class=\"p\">,</span> models<span class=\"o\">.</span>CASCADE<span class=\"p\">,</span> related_name<span class=\"o\">=</span><span class=\"s2\">&quot;supplies_given&quot;</span>\n    <span class=\"p\">)</span>\n    client <span class=\"o\">=</span> models<span class=\"o\">.</span>ForeignKey<span class=\"p\">(</span>\n        Manufacturer<span class=\"p\">,</span> models<span class=\"o\">.</span>CASCADE<span class=\"p\">,</span> related_name<span class=\"o\">=</span><span class=\"s2\">&quot;supplies_received&quot;</span>\n    <span class=\"p\">)</span>\n    product <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</code></pre></div>\n<p>Here, the <code class=\"docutils literal notranslate\">Manufacturer</code> model defines the many-to-many relationship\nwith <code class=\"docutils literal notranslate\">clients</code> in its role as a supplier. Therefore, the <code class=\"docutils literal notranslate\">supplier</code>\nforeign key (the source) must come before the <code class=\"docutils literal notranslate\">client</code> foreign key\n(the target) in the intermediary <code class=\"docutils literal notranslate\">Supply</code> model.</p>\n<p>Specifying <a class=\"reference internal\" href=\"#django.db.models.ManyToManyField.through_fields\" title=\"django.db.models.ManyToManyField.through_fields\"><code class=\"xref py py-attr docutils literal notranslate\">through_fields=(&quot;supplier&quot;, &quot;client&quot;)</code></a> on the <code class=\"docutils literal notranslate\">ManyToManyField</code> makes the\norder of foreign keys on the <code class=\"docutils literal notranslate\">through</code> model irrelevant.</p>\n</aside>\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, a\nprimary key and two foreign keys. There is a unique constraint on the two\nforeign keys.</p>\n<p>Jika sumber dan sasarn model berbeda, bidang-bidang berikut akan dibangkitkan:</p>\n<ul class=\"simple\">\n<li><p><code class=\"docutils literal notranslate\">id</code>: primary key dari hubungan.</p></li>\n<li><p><code class=\"docutils literal notranslate\">&lt;containing_model&gt;_id</code>: <code class=\"docutils literal notranslate\">id</code> dari model yang menyatakan <code class=\"docutils literal notranslate\">ManyToManyField</code>.</p></li>\n<li><p><code class=\"docutils literal notranslate\">&lt;other_model&gt;_id</code>: <code class=\"docutils literal notranslate\">id</code> dari model yang menunjuk pada <code class=\"docutils literal notranslate\">ManyToManyField</code>.</p></li>\n</ul>\n<p>Jika <code class=\"docutils literal notranslate\">ManyToManyField</code> menunjuk dari dan ke model sama, bidang-bidang berikut dibangkitkan:</p>\n<ul class=\"simple\">\n<li><p><code class=\"docutils literal notranslate\">id</code>: primary key dari hubungan.</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>: <code class=\"docutils literal notranslate\">id</code> dari instance dimana hubungan menunjuk (yaitu sasaran instance model).</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<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>Model<span class=\"o\">.</span>m2mfield<span class=\"o\">.</span>through<span class=\"o\">.</span>objects<span class=\"o\">.</span>all<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.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\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\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=\"s2\">&quot;Membership&quot;</span><span class=\"p\">,</span>\n        through_fields<span class=\"o\">=</span><span class=\"p\">(</span><span class=\"s2\">&quot;group&quot;</span><span class=\"p\">,</span> <span class=\"s2\">&quot;person&quot;</span><span class=\"p\">),</span>\n    <span class=\"p\">)</span>\n\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</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>Anda mempunyai warisan data yang tidak sah.</p></li>\n<li><p>Anda sedang memecah basisdata anda.</p></li>\n</ul>\n<p>Itu adalah sebuah kesalahan untuk melewatkan kedua <code class=\"docutils literal notranslate\">db_constraint</code> dan <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\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 pointing at a swappable model. If it is\n<code class=\"docutils literal notranslate\">True</code> - the default - then 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\nat a model which matches the current value of <code class=\"docutils literal notranslate\">settings.AUTH_USER_MODEL</code>\n(or another swappable model setting) the relationship will be stored in the\nmigration using a 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 toward the swapped-in model - for example,\nif it is a profile model designed specifically for your custom user model.</p>\n<p>Jika dalam keraguan, tinggalkan itu ke awalan menjadi <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> tidak mendukung <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> tidak mempunyai pengaruh sejak tidak ada cara untuk membutuhkan hubungan pada tingkat basisdata.</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\">to</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<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=\"/id/6.0/topics/db/models/#multi-table-inheritance\"><span class=\"std std-ref\">Warisan banyak-tabel</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 the\n<code class=\"docutils literal notranslate\">OneToOneField</code>, Django will use the lowercase name of the current model as\ndefault value.</p>\n<p>Dengan contoh berikut:</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\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=\"s2\">&quot;supervisor_of&quot;</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=\"pycon\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python console</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=\"Python console 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=\"s2\">&quot;myspecialuser&quot;</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=\"s2\">&quot;supervisor_of&quot;</span><span class=\"p\">)</span>\n<span class=\"go\">True</span>\n</code></pre></div>\n<p>A <code class=\"docutils literal notranslate\">RelatedObjectDoesNotExist</code> exception is raised when accessing the reverse\nrelationship if an entry in the related table doesn't exist. This is a subclass\nof the target model's <a class=\"reference internal\" href=\"/id/6.0/ref/models/class/#django.db.models.Model.DoesNotExist\" title=\"django.db.models.Model.DoesNotExist\"><code class=\"xref py py-exc docutils literal notranslate\">Model.DoesNotExist</code></a> exception and can be accessed as an\nattribute of the reverse accessor. For example, if a user doesn't have a\nsupervisor 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=\"k\">try</span><span class=\"p\">:</span>\n    user<span class=\"o\">.</span>supervisor_of\n<span class=\"k\">except</span> User<span class=\"o\">.</span>supervisor_of<span class=\"o\">.</span>RelatedObjectDoesNotExist<span class=\"p\">:</span>\n    <span class=\"k\">pass</span>\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=\"/id/6.0/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>Lihat <a class=\"reference internal\" href=\"/id/6.0/topics/db/examples/one_to_one/\"><span class=\"doc\">One-to-one relationships</span></a> untuk contoh penggunaan dari <code class=\"docutils literal notranslate\">OneToOneField</code>.</p>\n</section>\n<section id=\"lazy-relationships\">\n<span id=\"id4\"></span><h3>Lazy relationships<a class=\"heading-anchor\" href=\"#lazy-relationships\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>Lazy relationships allow referencing models by their names (as strings) or\ncreating recursive relationships. Strings can be used as the first argument in\nany relationship field to reference models lazily. A lazy reference can be\neither <a class=\"reference internal\" href=\"#recursive-relationships\"><span class=\"std std-ref\">recursive</span></a>,\n<a class=\"reference internal\" href=\"#relative-relationships\"><span class=\"std std-ref\">relative</span></a> or\n<a class=\"reference internal\" href=\"#absolute-relationships\"><span class=\"std std-ref\">absolute</span></a>.</p>\n<section id=\"recursive\">\n<span id=\"recursive-relationships\"></span><h4>Recursive<a class=\"heading-anchor\" href=\"#recursive\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>To define a relationship where a model references itself, use <code class=\"docutils literal notranslate\">&quot;self&quot;</code> as the\nfirst argument of the relationship field:</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\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    name <span class=\"o\">=</span> models<span class=\"o\">.</span>TextField<span class=\"p\">()</span>\n    suppliers <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> symmetrical<span class=\"o\">=</span><span class=\"kc\">False</span><span class=\"p\">)</span>\n</code></pre></div>\n<p>When used in an <a class=\"reference internal\" href=\"/id/6.0/topics/db/models/#abstract-base-classes\"><span class=\"std std-ref\">abstract model</span></a>, the recursive\nrelationship resolves such that each concrete subclass references itself.</p>\n</section>\n<section id=\"relative\">\n<span id=\"relative-relationships\"></span><h4>Relative<a class=\"heading-anchor\" href=\"#relative\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>When a relationship needs to be created with a model that has not been defined\nyet, it can be referenced by its name 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\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=\"s2\">&quot;Manufacturer&quot;</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\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    name <span class=\"o\">=</span> models<span class=\"o\">.</span>TextField<span class=\"p\">()</span>\n    suppliers <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> symmetrical<span class=\"o\">=</span><span class=\"kc\">False</span><span class=\"p\">)</span>\n</code></pre></div>\n<p>Relationships defined this way on <a class=\"reference internal\" href=\"/id/6.0/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=\"python\"><figcaption class=\"code-block-caption\"><code class=\"docutils literal notranslate\">products/models.py</code></figcaption>\n<div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python</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=\"Python code\"><code><span class=\"kn\">from</span> <span class=\"nn\">django.db</span> <span class=\"kn\">import</span> models\n\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=\"s2\">&quot;Manufacturer&quot;</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=\"python\"><figcaption class=\"code-block-caption\"><code class=\"docutils literal notranslate\">production/models.py</code></figcaption>\n<div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python</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=\"Python code\"><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\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    name <span class=\"o\">=</span> models<span class=\"o\">.</span>TextField<span class=\"p\">()</span>\n\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</code></pre></figure>\n<p>In this example, the <code class=\"docutils literal notranslate\">Car.manufacturer</code> relationship will resolve to\n<code class=\"docutils literal notranslate\">production.Manufacturer</code>, as it points to the concrete model defined\nwithin the <code class=\"docutils literal notranslate\">production/models.py</code> file.</p>\n<aside class=\"admonition-reusable-models-with-relative-references admonition\" role=\"note\">\n<p class=\"admonition-title\">Reusable models with relative references</p>\n<p>Relative references allow the creation of reusable abstract models with\nrelationships that can resolve to different implementations of the\nreferenced models in various subclasses across different applications.</p>\n</aside>\n</section>\n<section id=\"absolute\">\n<span id=\"absolute-relationships\"></span><h4>Absolute<a class=\"heading-anchor\" href=\"#absolute\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>Absolute references specify a model using its <code class=\"docutils literal notranslate\">app_label</code> and class name,\nallowing for model references across different applications. This type of lazy\nrelationship can also help resolve circular imports.</p>\n<p>For example, if the <code class=\"docutils literal notranslate\">Manufacturer</code> model is defined in another application\ncalled <code class=\"docutils literal notranslate\">thirdpartyapp</code>, it can be referenced as:</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=\"s2\">&quot;thirdpartyapp.Manufacturer&quot;</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>Absolute references always point to the same model, even when used in an\n<a class=\"reference internal\" href=\"/id/6.0/topics/db/models/#abstract-base-classes\"><span class=\"std std-ref\">abstract model</span></a>.</p>\n</section>\n</section>\n</section>\n<section id=\"field-api-reference\">\n<h2>Acuan API Bidang<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=\"/id/6.0/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=\"/id/6.0/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=\"/id/6.0/topics/db/models/\"><span class=\"doc\">Model</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>Sebuah <code class=\"docutils literal notranslate\">Field</code> adalah subkelas dari <a class=\"reference internal\" href=\"/id/6.0/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> dan dengan demikian kedua <a class=\"reference internal\" href=\"/id/6.0/ref/models/lookups/#django.db.models.Transform\" title=\"django.db.models.Transform\"><code class=\"xref py py-class docutils literal notranslate\">Transform</code></a> dan <a class=\"reference internal\" href=\"/id/6.0/ref/models/lookups/#django.db.models.Lookup\" title=\"django.db.models.Lookup\"><code class=\"xref py py-class docutils literal notranslate\">Lookup</code></a> dapat didaftarkan pada itu untuk digunakan dalam (misalnya <code class=\"docutils literal notranslate\">field_name__exact=&quot;foo&quot;</code>) <code class=\"docutils literal notranslate\">QuerySet</code>. Semua <a class=\"reference internal\" href=\"/id/6.0/ref/models/querysets/#field-lookups\"><span class=\"std std-ref\">built-in lookups</span></a> didaftarkan secara awalan.</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=\"/id/6.0/howto/custom-model-fields/\"><span class=\"doc\">Bagaimana membuat bidang model disesuaikan</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>Gambaran bertele-tele dari bidang, misalnya aplikasi <a class=\"reference internal\" href=\"/id/6.0/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>.</p>\n<p>Gambaran dapat berupa dari bentuk</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>dimana argumen-argumen ditambahkan dari <code class=\"docutils literal notranslate\">__dict__</code> bidang-bidang.</p>\n</dd></dl>\n\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.Field.descriptor_class\">\n<span class=\"sig-name descname\">descriptor_class</span><a class=\"heading-anchor\" href=\"#django.db.models.Field.descriptor_class\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>A class implementing the <a class=\"reference external\" href=\"https://docs.python.org/3/reference/datamodel.html#descriptors\" title=\"(di Python v3.14)\"><span class=\"xref std std-ref\">descriptor protocol</span></a>\nthat is instantiated and assigned to the model instance attribute. The\nconstructor must accept a single argument, the <code class=\"docutils literal notranslate\">Field</code> instance.\nOverriding this class attribute allows for customizing the get and set\nbehavior.</p>\n</dd></dl>\n\n<p>Untuk memetakan sebuah <code class=\"docutils literal notranslate\">Field</code> pada jenis khusus-basisdata, Django membuka beberapa metode-metode:</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>Mengembalikan sebuah string menamakan bidang ini untuk tujuan khusus backend. Secara awalan, itu mengembalikan nama kelas.</p>\n<p>Lihat <a class=\"reference internal\" href=\"/id/6.0/howto/custom-model-fields/#emulating-built-in-field-types\"><span class=\"std std-ref\">Menyamai jenis bidang siap pakai</span></a> untuk penggunaan dalam bidang penyesuaian.</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>Mengembalikan jenis data kolom basisdata untuk  <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>, dimasukkan kedalam akun <code class=\"docutils literal notranslate\">connection</code>.</p>\n<p>Lihat <a class=\"reference internal\" href=\"/id/6.0/howto/custom-model-fields/#custom-database-types\"><span class=\"std std-ref\">Jenis basisdata penyesuaian</span></a> untuk penggunaan dalam bidang penyesuaian.</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><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>Lihat <a class=\"reference internal\" href=\"/id/6.0/howto/custom-model-fields/#custom-database-types\"><span class=\"std std-ref\">Jenis basisdata penyesuaian</span></a> untuk penggunaan dalam bidang penyesuaian.</p>\n</dd></dl>\n\n<p>Ada tiga keadaan utama dimana Django butuh berinteraksi dengan backend basisdata dan bidang-bidang:</p>\n<ul class=\"simple\">\n<li><p>ketika itu meminta basisdata (nilai Python -&gt; nilai backend basisdata)</p></li>\n<li><p>ketika itu memuat data dari basisdata (nilai backend basisdata -&gt; nilai Python)</p></li>\n<li><p>ketika itu menyimpan ke basisdata (nilai Python -&gt; nilai backend basisdata)</p></li>\n</ul>\n<p>Ketika meminta, <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> dan <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> digunakan:</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> adalah nilai saat ini dari atribut model, dan metode harus mengembalikan data dalam bentuk yang telah dipersiapkan untuk digunakan sebagai sebuah parameter dalam sebuah permintaan.</p>\n<p>Lihat <a class=\"reference internal\" href=\"/id/6.0/howto/custom-model-fields/#converting-python-objects-to-query-values\"><span class=\"std std-ref\">Mengubah obyek Python ke nilai pencarian</span></a> untuk penggunaan.</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(value)</code></a> otherwise.</p>\n<p>Lihat <a class=\"reference internal\" href=\"/id/6.0/howto/custom-model-fields/#converting-query-values-to-database-values\"><span class=\"std std-ref\">Mengubah nilai pencarian ke nilai basisdata</span></a> untuk penggunaan.</p>\n</dd></dl>\n\n<p>Ketika memuat 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> digunakan:</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><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>Merubah nilai ketika dikembalikan oleh basisdata ke obyek Python. Itu adalah balikan dari <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>Metode ini tidak digunakan untuk kebanyakan bidang-bidang siap-pakai ketika backend basisdata sudah mengembalikan jenis Python yang benar, atau backend itu sendiri melakukan perubahan.</p>\n<p><code class=\"docutils literal notranslate\">expression</code> is the same as <code class=\"docutils literal notranslate\">self</code>.</p>\n<p>Lihat <a class=\"reference internal\" href=\"/id/6.0/howto/custom-model-fields/#converting-values-to-python-objects\"><span class=\"std std-ref\">Mengubah nilai menjadi obyek Python</span></a> untuk penggunaan.</p>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">Catatan</p>\n<p>Untuk alasan penampilan, <code class=\"docutils literal notranslate\">from_db_value</code> tidak diterapkan sebagai sebuah no-op pada bidang-bidang yang tidak membutuhkan itu (semua bidang-bidang Django). Karena itu anda mungkin tidak memanggil <code class=\"docutils literal notranslate\">super</code> dalam penentuan anda.</p>\n</aside>\n</dd></dl>\n\n<p>Ketika menyimpan,  <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> dan <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> digunakan:</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>Lihat <a class=\"reference internal\" href=\"/id/6.0/howto/custom-model-fields/#preprocessing-values-before-saving\"><span class=\"std std-ref\">Mengolah nilai sebelum menyimpan</span></a> untuk penggunaan.</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=\"/id/6.0/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>Lihat <a class=\"reference internal\" href=\"/id/6.0/howto/custom-model-fields/#converting-values-to-python-objects\"><span class=\"std std-ref\">Mengubah nilai menjadi obyek Python</span></a> untuk penggunaan.</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_from_object\">\n<span class=\"sig-name descname\">value_from_object</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_from_object\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Returns the field's value for the given model instance.</p>\n<p>Metode ini sering digunakan oleh <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>.</p>\n</dd></dl>\n\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>Merubah <code class=\"docutils literal notranslate\">obj</code> menjadi sebuah string. Digunakan untuk menserialisasikan nilai dari bidang.</p>\n<p>Lihat <a class=\"reference internal\" href=\"/id/6.0/howto/custom-model-fields/#converting-model-field-to-serialization\"><span class=\"std std-ref\">Mengubah data field untuk serialisasi</span></a> untuk penggunaan.</p>\n</dd></dl>\n\n<p>Ketika menggunakan <a class=\"reference internal\" href=\"/id/6.0/topics/forms/modelforms/#django.forms.ModelForm\" title=\"django.forms.ModelForm\"><code class=\"xref py py-class docutils literal notranslate\">model forms</code></a>, <code class=\"docutils literal notranslate\">Field</code> butuh mengetahui bidang formulir mana itu harus diwakili:</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>Mengembalikan <a class=\"reference internal\" href=\"/id/6.0/ref/forms/fields/#django.forms.Field\" title=\"django.forms.Field\"><code class=\"xref py py-class docutils literal notranslate\">django.forms.Field</code></a> awalan dari bidang ini untuk  <a class=\"reference internal\" href=\"/id/6.0/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>If <a class=\"reference internal\" href=\"#django.db.models.Field.formfield\" title=\"django.db.models.Field.formfield\"><code class=\"xref py py-meth docutils literal notranslate\">formfield()</code></a> is overridden to return <code class=\"docutils literal notranslate\">None</code>, this\nfield is excluded from the <a class=\"reference internal\" href=\"/id/6.0/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>Secara awalan, jika kedua <code class=\"docutils literal notranslate\">form_class</code> dan <code class=\"docutils literal notranslate\">choices_form_class</code> adalah <code class=\"docutils literal notranslate\">None</code>, itu menggunakan <a class=\"reference internal\" href=\"/id/6.0/ref/forms/fields/#django.forms.CharField\" title=\"django.forms.CharField\"><code class=\"xref py py-class docutils literal notranslate\">CharField</code></a>. Jika bidang mempunyai <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> dan <code class=\"docutils literal notranslate\">choices_form_class</code> tidak ditentukan, itu menggunakan <a class=\"reference internal\" href=\"/id/6.0/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>Lihat <a class=\"reference internal\" href=\"/id/6.0/howto/custom-model-fields/#specifying-form-field-for-model-field\"><span class=\"std std-ref\">Menentukan bidang formulir untuk sebuah bidang model</span></a>  untuk penggunaan.</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>Mengembalikan 4-tuple dengan informasi cukup untuk membuat kembali bidang:</p>\n<ol class=\"arabic simple\">\n<li><p>Nama dari bidang pada model.</p></li>\n<li><p>Jalur impor dari bidang (misalnya <code class=\"docutils literal notranslate\">&quot;django.db.models.IntegerField&quot;</code>). Ini harus versi paling ringan, jadi kurang spesifik mungkin lebih baik.</p></li>\n<li><p>Daftar dari argumen penempatan.</p></li>\n<li><p>Sebuah dict dari argumen kata kunci.</p></li>\n</ol>\n<p>Metode ini harus ditambahkan pada bidang sebekum 1.7 untuk memindahkan datanya menggunakan <a class=\"reference internal\" href=\"/id/6.0/topics/migrations/\"><span class=\"doc\">Perpindahan</span></a>.</p>\n</dd></dl>\n\n</dd></dl>\n\n</section>\n<section id=\"registering-and-fetching-lookups\">\n<h2>Pencarian pendaftaran dan pengambilan<a class=\"heading-anchor\" href=\"#registering-and-fetching-lookups\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p><code class=\"docutils literal notranslate\">Field</code> implements the <a class=\"reference internal\" href=\"/id/6.0/ref/models/lookups/#lookup-registration-api\"><span class=\"std std-ref\">lookup registration API</span></a>. The API can be used to customize which lookups are\navailable for a field class and its instances, and how lookups are fetched from\na field.</p>\n</section>\n</section>\n<section id=\"field-attribute-reference\">\n<span id=\"model-field-attributes\"></span><h1>Acuan atribut bidang<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=\"/id/6.0/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>Atribut untuk bidang<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>Bendera Boolean yang menunjukkan jika bidang otomatis dibuat, seperti <code class=\"docutils literal notranslate\">OneToOneField</code> digunakan oleh warisan model.</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>Bendera Boolean mengindikasikan jika bidang mempunyai kolom terkait dengan itu.</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 hidden and should not be returned\nby <a class=\"reference internal\" href=\"/id/6.0/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> by default. An example is\nthe reverse field for 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> with a\n<code class=\"docutils literal notranslate\">related_name</code> that starts with <code class=\"docutils literal notranslate\">'+'</code>.</p>\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>Bendera Boolean yang menunjukkan jika sebuah bidang mengandung acuan ke satu atau lebih model untuk kegunaannya (misalnya <code class=\"docutils literal notranslate\">ForeignKey</code>, <code class=\"docutils literal notranslate\">ManyToManyField</code>, <code class=\"docutils literal notranslate\">OneToOneField</code>, dll.).</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>Atribut untuk bidang dengan hubungan<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>Bendera Boolean adalah <code class=\"docutils literal notranslate\">True</code> jika bidang mempunyai hubungan many-to-many; <code class=\"docutils literal notranslate\">False</code> sebaliknya. Hanya bidang disertakan dengan Django dimana ini adalah <code class=\"docutils literal notranslate\">True</code> adalah <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>Bendera Boolean adalah <code class=\"docutils literal notranslate\">True</code> jika bidang mempunyai hubungan many-to-one, seperti <code class=\"docutils literal notranslate\">ForeignKey</code>; <code class=\"docutils literal notranslate\">False</code> sebaliknya.</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>Bendera Boolean adalah <code class=\"docutils literal notranslate\">True</code> jika bidang mempunyai hubungan one-to-many, seperti <code class=\"docutils literal notranslate\">GenericRelation</code> atau kebalikan dari <code class=\"docutils literal notranslate\">ForeignKey</code>; <code class=\"docutils literal notranslate\">False</code> sebaliknya.</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>Bendera Boolean adalah <code class=\"docutils literal notranslate\">True</code> jika bidang mempunyai hubungan one-to-one, seperti <code class=\"docutils literal notranslate\">OneToOneField</code>; <code class=\"docutils literal notranslate\">False</code> sebaliknya.</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":"Acuan bidang model","anchor":"","children":[{"title":"Pilihan bidang","anchor":"field-options","children":[{"title":"null","anchor":"null","children":[]},{"title":"blank","anchor":"blank","children":[]},{"title":"choices","anchor":"choices","children":[{"title":"Enumeration types","anchor":"enumeration-types","children":[]}]},{"title":"db_column","anchor":"db-column","children":[]},{"title":"db_comment","anchor":"db-comment","children":[]},{"title":"db_default","anchor":"db-default","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":"unik","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":"Jenis bidang","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":"CompositePrimaryKey","anchor":"compositeprimarykey","children":[]},{"title":"CharField","anchor":"charfield","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 dan FieldFile","anchor":"filefield-and-fieldfile","children":[]}]},{"title":"FilePathField","anchor":"filepathfield","children":[]},{"title":"FloatField","anchor":"floatfield","children":[]},{"title":"GeneratedField","anchor":"generatedfield","children":[]},{"title":"GenericIPAddressField","anchor":"genericipaddressfield","children":[]},{"title":"ImageField","anchor":"imagefield","children":[]},{"title":"IntegerField","anchor":"integerfield","children":[]},{"title":"JSONField","anchor":"jsonfield","children":[]},{"title":"PositiveBigIntegerField","anchor":"positivebigintegerfield","children":[]},{"title":"PositiveIntegerField","anchor":"positiveintegerfield","children":[]},{"title":"PositiveSmallIntegerField","anchor":"positivesmallintegerfield","children":[]},{"title":"SlugField","anchor":"slugfield","children":[]},{"title":"SmallAutoField","anchor":"smallautofield","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":"Bidang hubungan","anchor":"module-django.db.models.fields.related","children":[{"title":"ForeignKey","anchor":"foreignkey","children":[{"title":"Perwakilan Basisdata","anchor":"database-representation","children":[]},{"title":"Penjelasan","anchor":"arguments","children":[]}]},{"title":"ManyToManyField","anchor":"manytomanyfield","children":[{"title":"Perwakilan Basisdata","anchor":"id2","children":[]},{"title":"Penjelasan","anchor":"manytomany-arguments","children":[]}]},{"title":"OneToOneField","anchor":"onetoonefield","children":[]},{"title":"Lazy relationships","anchor":"lazy-relationships","children":[{"title":"Recursive","anchor":"recursive","children":[]},{"title":"Relative","anchor":"relative","children":[]},{"title":"Absolute","anchor":"absolute","children":[]}]}]},{"title":"Acuan API Bidang","anchor":"field-api-reference","children":[]},{"title":"Pencarian pendaftaran dan pengambilan","anchor":"registering-and-fetching-lookups","children":[]}]},{"title":"Acuan atribut bidang","anchor":"field-attribute-reference","children":[{"title":"Atribut untuk bidang","anchor":"attributes-for-fields","children":[]},{"title":"Atribut untuk bidang dengan hubungan","anchor":"attributes-for-fields-with-relations","children":[]}]}],"breadcrumbs":[{"docname":"ref/index","title":"Acuan API","url":"/id/6.0/ref/"},{"docname":"ref/models/index","title":"Model","url":"/id/6.0/ref/models/"}],"prev":{"docname":"ref/models/index","title":"Model","url":"/id/6.0/ref/models/"},"next":{"docname":"ref/models/indexes","title":"Acuan index model","url":"/id/6.0/ref/models/indexes/"},"formats":{"html":"/id/6.0/ref/models/fields/","markdown":"/id/6.0/ref/models/fields.md","json":"/id/6.0/ref/models/fields.json"},"source":"https://github.com/django/django/blob/stable/6.0.x/docs/ref/models/fields.txt","official":"https://docs.djangoproject.com/id/6.0/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","sv","zh-hans","ga","fr","ja","id","it","pt-br","ko","es","el","pl"]}