Opened 6 years ago

Closed 6 years ago

Last modified 5 years ago

#13269 closed (fixed)

"Overriding the default widgets" docs missing import statement

Reported by: mattrowbum Owned by: gabrielhurley
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: UI/UX:



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...

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)

13269_modelform_docs.diff (875 bytes) - added by gabrielhurley 6 years ago.

Download all attachments as: .zip

Change History (6)

comment:1 Changed 6 years ago by gabrielhurley

  • milestone set to 1.2
  • Needs documentation unset
  • Needs tests unset
  • Owner changed from nobody to gabrielhurley
  • Patch needs improvement unset
  • Status changed from new to assigned
  • Summary changed from Possible docs error - Overriding the default field types or widgets to "Overriding the default widgets" docs missing import statement
  • Triage Stage changed from Unreviewed to Accepted

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, TextArea would also work.

Trivial docs ticket to add to 1.2. I'll write up a patch a little later today.

Changed 6 years ago by gabrielhurley

comment:2 Changed 6 years ago by gabrielhurley

  • Has patch set

Clarified example text (fixing a typo in the process), and added proper import statement to example.

comment:3 Changed 6 years ago by timo

  • Triage Stage changed from Accepted to Ready for checkin

comment:4 Changed 6 years ago by russellm

  • Resolution set to fixed
  • Status changed from assigned to closed

(In [13130]) Fixed #13269 -- Added clarifying import statement to widget override docs. Thanks to mattrowbum for the report, and Gabriel Hurley for the patch.

comment:5 Changed 5 years ago by jacob

  • milestone 1.2 deleted

Milestone 1.2 deleted

Note: See TracTickets for help on using tickets.
Back to Top