#13269 closed (fixed)
"Overriding the default widgets" docs missing import statement
| Reported by: | Matthew Rowbottom | Owned by: | Gabriel Hurley |
|---|---|---|---|
| Component: | Documentation | Version: | 1.2-beta |
| Severity: | Keywords: | widgets, form field types | |
| Cc: | Triage Stage: | Ready for checkin | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
Hi.
I'm new to django and am using the development version from SVN v1.2.0 beta.1 (rev 12909)
I am unsure of whether there is a problem in the code, docs or my own app. I'm providing this as a solution to a problem I faced, based on information found in the docs.
The first example given in the following section of the docs would not work for me...
http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#overriding-the-default-field-types-or-widgets
class AuthorForm(ModelForm):
class Meta:
model = Author
fields = ['name', 'title', 'birth_date']
widgets = {
'name': Textarea(attrs={'cols': 80, 'rows': 20}),
}
From reading through the docs, I presume that the only import required is:
from django.forms import ModelForm
When I attempted to run the development server, I receive the following error message:
NameError: name 'Textarea' is not defined
My solution was the following:
from django import forms
class AuthorForm(forms.ModelForm):
class Meta:
model = Author
fields = ['name', 'title', 'birth_date']
widgets = {
'name': forms.Textarea(attrs={'cols': 80, 'rows': 20}),
}
In summary, I made the following changes:
Line 1 - from django import forms Line 3 - class AuthorForm(forms.ModelForm): Line 8 - 'name': forms.Textarea(...),
I hope this is of some help.
Attachments (1)
Change History (6)
comment:1 by , 16 years ago
| milestone: | → 1.2 |
|---|---|
| Owner: | changed from to |
| Status: | new → assigned |
| Summary: | Possible docs error - Overriding the default field types or widgets → "Overriding the default widgets" docs missing import statement |
| Triage Stage: | Unreviewed → Accepted |
by , 16 years ago
| Attachment: | 13269_modelform_docs.diff added |
|---|
comment:2 by , 16 years ago
| Has patch: | set |
|---|
Clarified example text (fixing a typo in the process), and added proper import statement to example.
comment:3 by , 16 years ago
| Triage Stage: | Accepted → Ready for checkin |
|---|
comment:4 by , 16 years ago
| Resolution: | → fixed |
|---|---|
| Status: | assigned → closed |
Yeah, there is a problem there. At no point on the page does it actually import TextArea. Your solution is one way to fix it, or simply changing it to
from django.forms import ModelForm, TextAreawould also work.Trivial docs ticket to add to 1.2. I'll write up a patch a little later today.