summaryrefslogtreecommitdiff
path: root/docs/newforms.txt
diff options
context:
space:
mode:
authorBrian Rosner <brosner@gmail.com>2008-07-06 15:23:24 +0000
committerBrian Rosner <brosner@gmail.com>2008-07-06 15:23:24 +0000
commit8c8513281e9ed29840a082c05482a87d33f59f96 (patch)
treecfeb54f6adaeac83f8e009773bac81ab48b02a29 /docs/newforms.txt
parent058a190a792fd1ffc5b0f9c522ce805ea58d655b (diff)
newforms-admin: Merged from trunk up to [7852].
git-svn-id: http://code.djangoproject.com/svn/django/branches/newforms-admin@7853 bcc190cf-cafb-0310-a4f2-bffc1f526a37
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):