From 8aa1efff6d6cb1589a1977f3e68f4c26eb6adc74 Mon Sep 17 00:00:00 2001 From: Alasdair Nicol Date: Sun, 9 Feb 2014 11:38:13 +0000 Subject: Fixed #21951 -- Updated docs to use __str__ for Python 3 Thanks Tim Graham for the report and recommendations --- docs/ref/forms/api.txt | 14 +++++++------- docs/ref/forms/fields.txt | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'docs/ref/forms') diff --git a/docs/ref/forms/api.txt b/docs/ref/forms/api.txt index fbc025f18c..7f2de3fa03 100644 --- a/docs/ref/forms/api.txt +++ b/docs/ref/forms/api.txt @@ -653,16 +653,16 @@ Customizing the error list format By default, forms use ``django.forms.utils.ErrorList`` to format validation errors. If you'd like to use an alternate class for displaying errors, you can -pass that in at construction time (replace ``__unicode__`` by ``__str__`` on -Python 3):: +pass that in at construction time (replace ``__str__`` by ``__unicode__`` on +Python 2):: >>> from django.forms.utils import ErrorList >>> class DivErrorList(ErrorList): - ... def __unicode__(self): + ... def __str__(self): # __unicode__ on Python 2 ... return self.as_divs() ... def as_divs(self): - ... if not self: return u'' - ... return u'
%s
' % ''.join([u'
%s
' % e for e in self]) + ... if not self: return '' + ... return '
%s
' % ''.join(['
%s
' % e for e in self]) >>> f = ContactForm(data, auto_id=False, error_class=DivErrorList) >>> f.as_p()
This field is required.
@@ -687,8 +687,8 @@ lazy developers -- they're not the only way a form object can be displayed. Used to display HTML or access attributes for a single field of a :class:`Form` instance. - The ``__unicode__()`` and ``__str__()`` methods of this object displays - the HTML for this field. + The ``__str__()`` (``__unicode__`` on Python 2) method of this + object displays the HTML for this field. To retrieve a single ``BoundField``, use dictionary lookup syntax on your form using the field's name as the key:: diff --git a/docs/ref/forms/fields.txt b/docs/ref/forms/fields.txt index 42d639e8c7..f48f9ff4ad 100644 --- a/docs/ref/forms/fields.txt +++ b/docs/ref/forms/fields.txt @@ -1047,7 +1047,7 @@ objects (in the case of ``ModelMultipleChoiceField``) into the initial value, no empty choice is created (regardless of the value of ``empty_label``). - The ``__unicode__`` (``__str__`` on Python 3) 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 field's choices; to provide customized representations, subclass ``ModelChoiceField`` and override ``label_from_instance``. This method will -- cgit v1.3