Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
ad43fdaa
Kaydet (Commit)
ad43fdaa
authored
Mar 05, 2014
tarafından
Anubhav Joshi
Kaydeden (comit)
Tim Graham
Mar 16, 2014
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #21860 -- Added to_field_name to ModelChoiceField docs.
Thanks Keryn Knight for the suggestion.
üst
abade641
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
1 deletion
+35
-1
fields.txt
docs/ref/forms/fields.txt
+35
-1
No files found.
docs/ref/forms/fields.txt
Dosyayı görüntüle @
ad43fdaa
...
@@ -1027,7 +1027,7 @@ objects (in the case of ``ModelMultipleChoiceField``) into the
...
@@ -1027,7 +1027,7 @@ objects (in the case of ``ModelMultipleChoiceField``) into the
field will be derived, and which will be used to validate the
field will be derived, and which will be used to validate the
user's selection.
user's selection.
``ModelChoiceField`` also takes
one optional argument
:
``ModelChoiceField`` also takes
two optional arguments
:
.. attribute:: empty_label
.. attribute:: empty_label
...
@@ -1047,6 +1047,40 @@ objects (in the case of ``ModelMultipleChoiceField``) into the
...
@@ -1047,6 +1047,40 @@ objects (in the case of ``ModelMultipleChoiceField``) into the
initial value, no empty choice is created (regardless of the value
initial value, no empty choice is created (regardless of the value
of ``empty_label``).
of ``empty_label``).
.. attribute:: to_field_name
This optional argument is used to specify the field to use as the value
of the choices in the field's widget. By default it is set to ``None``,
in which case the primary key of each object will be used. For example::
# No custom to_field_name
field1 = forms.ModelChoiceField(queryset=...)
would yield:
.. code-block:: html
<select id="id_field1" name="field1">
<option value="obj1.pk">Object1</option>
<option value="obj2.pk">Object2</option>
...
</select>
and::
# to_field_name provided
field2 = forms.ModelChoiceField(queryset=..., to_field_name="name")
would yield:
.. code-block:: html
<select id="id_field2" name="field2">
<option value="obj1.name">Object1</option>
<option value="obj2.name">Object2</option>
...
</select>
The ``__str__`` (``__unicode__`` on Python 2) method of the model will be
The ``__str__`` (``__unicode__`` on Python 2) method of the model will be
called to generate string representations of the objects for use in the
called to generate string representations of the objects for use in the
field's choices; to provide customized representations, subclass
field's choices; to provide customized representations, subclass
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment