[1.7.x] Fixed #23354 -- Documented that ModelChoiceField to_field_name should be a unique field.

Thanks Keryn Knight for the suggestion.

Backport of 83762da3fb from master
This commit is contained in:
Tim Graham 2014-08-27 07:43:13 -04:00
parent 307eef20e3
commit e86030b3be
1 changed files with 4 additions and 2 deletions

View File

@ -1061,8 +1061,10 @@ method::
.. attribute:: to_field_name .. attribute:: to_field_name
This optional argument is used to specify the field to use as the value 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``, of the choices in the field's widget. Be sure it's a unique field for
in which case the primary key of each object will be used. For example:: the model, otherwise the selected value could match more than one
object. 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 # No custom to_field_name
field1 = forms.ModelChoiceField(queryset=...) field1 = forms.ModelChoiceField(queryset=...)