mirror of
https://github.com/django/django.git
synced 2025-03-09 00:42:40 +00:00
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
This commit is contained in:
parent
b24ad9a06b
commit
3fd5b5d6a8
@ -17,7 +17,7 @@ class from a Django model.
|
|||||||
For example::
|
For example::
|
||||||
|
|
||||||
>>> from django.newforms import ModelForm
|
>>> from django.newforms import ModelForm
|
||||||
|
|
||||||
# Create the form class.
|
# Create the form class.
|
||||||
>>> class ArticleForm(ModelForm):
|
>>> class ArticleForm(ModelForm):
|
||||||
... class Meta:
|
... class Meta:
|
||||||
@ -278,7 +278,7 @@ model fields:
|
|||||||
To avoid this failure, you must instantiate your model with initial values
|
To avoid this failure, you must instantiate your model with initial values
|
||||||
for the missing, but required fields, or use ``save(commit=False)`` and
|
for the missing, but required fields, or use ``save(commit=False)`` and
|
||||||
manually set any extra required fields::
|
manually set any extra required fields::
|
||||||
|
|
||||||
instance = Instance(required_field='value')
|
instance = Instance(required_field='value')
|
||||||
form = InstanceForm(request.POST, instance=instance)
|
form = InstanceForm(request.POST, instance=instance)
|
||||||
new_instance = form.save()
|
new_instance = form.save()
|
||||||
@ -311,3 +311,12 @@ field, you could do the following::
|
|||||||
...
|
...
|
||||||
... class Meta:
|
... class Meta:
|
||||||
... model = Article
|
... 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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user