summaryrefslogtreecommitdiff
path: root/docs/newforms.txt
diff options
context:
space:
mode:
Diffstat (limited to 'docs/newforms.txt')
-rw-r--r--docs/newforms.txt18
1 files changed, 12 insertions, 6 deletions
diff --git a/docs/newforms.txt b/docs/newforms.txt
index be3a0b6a2a..824bdb7ea1 100644
--- a/docs/newforms.txt
+++ b/docs/newforms.txt
@@ -1348,7 +1348,7 @@ An ``UploadedFile`` object has two attributes:
The string representation of an ``UploadedFile`` is the same as the filename
attribute.
-When you use a ``FileField`` on a form, you must also remember to
+When you use a ``FileField`` in a form, you must also remember to
`bind the file data to the form`_.
.. _`bind the file data to the form`: `Binding uploaded files to a form`_
@@ -1415,7 +1415,7 @@ These control the range of values permitted in the field.
Using an ImageField requires that the `Python Imaging Library`_ is installed.
-When you use a ``FileField`` on a form, you must also remember to
+When you use an ``ImageField`` in a form, you must also remember to
`bind the file data to the form`_.
.. _Python Imaging Library: http://www.pythonware.com/products/pil/
@@ -1820,15 +1820,21 @@ reuse certain sets of widget attributes over and over again. Rather than
repeat these attribute definitions every time you need them, Django allows
you to capture those definitions as a custom widget.
-For example, if you find that you are including a lot of comment fields on forms,
-you could capture the idea of a ``TextInput`` with a specific ``size`` attribute
-as a custom extension to the ``TextInput`` widget::
+For example, if you find that you are including a lot of comment fields on
+forms, you could capture the idea of a ``TextInput`` with a specific
+default ``size`` attribute as a custom extension to the ``TextInput`` widget::
class CommentWidget(forms.TextInput):
def __init__(self, *args, **kwargs):
- kwargs.setdefault('attrs',{}).update({'size': '40'})
+ attrs = kwargs.setdefault('attrs',{})
+ if 'size' not in attrs:
+ attrs['size'] = 40
super(CommentWidget, self).__init__(*args, **kwargs)
+We allow the ``size`` attribute to be overridden by the user, but, by default,
+this widget will behave as if ``attrs={'size': 40}`` was always passed into the
+constructor.
+
Then you can use this widget in your forms::
class CommentForm(forms.Form):