Opened 7 years ago

Closed 7 years ago

Last modified 5 years ago

#13269 closed (fixed)

"Overriding the default widgets" docs missing import statement

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

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)

13269_modelform_docs.diff (875 bytes) - added by Gabriel Hurley 7 years ago.

Download all attachments as: .zip

Change History (6)

comment:1 Changed 7 years ago by Gabriel Hurley

milestone: 1.2
Owner: changed from nobody to Gabriel Hurley
Status: newassigned
Summary: Possible docs error - Overriding the default field types or widgets"Overriding the default widgets" docs missing import statement
Triage Stage: UnreviewedAccepted

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 7 years ago by Gabriel Hurley

Attachment: 13269_modelform_docs.diff added

comment:2 Changed 7 years ago by Gabriel Hurley

Has patch: set

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

comment:3 Changed 7 years ago by Tim Graham

Triage Stage: AcceptedReady for checkin

comment:4 Changed 7 years ago by Russell Keith-Magee

Resolution: fixed
Status: assignedclosed

(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

Milestone 1.2 deleted

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