Skip to content

Commit

Permalink
Clean up some awkwardness and confusion in the docs for ``ModelChoice…
Browse files Browse the repository at this point in the history
…Field``

git-svn-id: http://code.djangoproject.com/svn/django/trunk@7386 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
ubernostrum committed Mar 30, 2008
1 parent a9ce132 commit b8110ed
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions docs/newforms.txt
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -1549,12 +1549,15 @@ additional required argument:
``ModelChoiceField`` ``ModelChoiceField``
~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~


Allows the selection of a single model object, suitable for representing a Allows the selection of a single model object, suitable for
foreign key. The method receives an object as an argument and must return a representing a foreign key.
string to represent it.


The labels for the choice field call the ``__unicode__`` method of the model to The labels for the choice field call the ``__unicode__`` method of the
generate string representations. To provide custom labels, subclass ``ModelChoiceField`` and override ``label_for_model``:: model to generate string representations to use in the field's
choices; to provide customized representations,, subclass
``ModelChoiceField`` and override ``label_for_model``; this method
will receive an object, and should return a string suitable for
representing it::


class MyModelChoiceField(ModelChoiceField): class MyModelChoiceField(ModelChoiceField):
def label_from_instance(self, obj): def label_from_instance(self, obj):
Expand All @@ -1563,9 +1566,10 @@ generate string representations. To provide custom labels, subclass ``ModelChoic
``ModelMultipleChoiceField`` ``ModelMultipleChoiceField``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Allows the selection of one or more model objects, suitable for representing a Allows the selection of one or more model objects, suitable for
many-to-many relation. As with ``ModelChoiceField``, you can use representing a many-to-many relation. As with ``ModelChoiceField``,
``label_from_instance`` to customize the object labels. you can use ``label_from_instance`` to customize the object
representations.


Creating custom fields Creating custom fields
---------------------- ----------------------
Expand Down

0 comments on commit b8110ed

Please sign in to comment.