diff options
| author | Gary Wilson Jr <gary.wilson@gmail.com> | 2008-01-28 03:12:28 +0000 |
|---|---|---|
| committer | Gary Wilson Jr <gary.wilson@gmail.com> | 2008-01-28 03:12:28 +0000 |
| commit | 3fd5b5d6a8a7caf284a7ca0d351b17d651b93955 (patch) | |
| tree | 820eaca9f6a2bb42f75c64172070ceebafef9e19 /docs | |
| parent | b24ad9a06b3954a23da1f38a5811c1714742ba3b (diff) | |
Fixed #6265 -- Added an example of overriding a form field's default widget in the modelforms docs, based on patch from programmerq.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7036 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/modelforms.txt | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/docs/modelforms.txt b/docs/modelforms.txt index c8265391f5..a99e27fff7 100644 --- a/docs/modelforms.txt +++ b/docs/modelforms.txt @@ -17,7 +17,7 @@ class from a Django model. For example:: >>> from django.newforms import ModelForm - + # Create the form class. >>> class ArticleForm(ModelForm): ... class Meta: @@ -278,7 +278,7 @@ model fields: To avoid this failure, you must instantiate your model with initial values for the missing, but required fields, or use ``save(commit=False)`` and manually set any extra required fields:: - + instance = Instance(required_field='value') form = InstanceForm(request.POST, instance=instance) new_instance = form.save() @@ -311,3 +311,12 @@ field, you could do the following:: ... ... class Meta: ... model = Article + +If you want to override a field's default widget, then specify the ``widget`` +parameter when declaring the form field:: + + >>> class ArticleForm(ModelForm): + ... pub_date = DateField(widget=MyDateWidget()) + ... + ... class Meta: + ... model = Article |
