Opened 16 years ago

Closed 16 years ago

#6328 closed (invalid)

ModelForm doc mistake?

Reported by: LongMan <alx.gsv@…> Owned by: nobody
Component: Documentation Version: dev
Severity: Keywords: newforms
Cc: alx.gsv@…, thejaswi.puthraya@… Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I read that i can create form to add an article with no parameters:

# Create the form class.
>>> class ArticleForm(ModelForm):
...     class Meta:
...         model = Article

# Creating a form to add an article.
>>> form = ArticleForm()

But, newforms/models.py

class BaseModelForm(BaseForm):
    def __init__(self, instance, data=None, files=None, auto_id='id_%s', prefix=None,
                 initial=None, error_class=ErrorList, label_suffix=':'):
        ...

requires 1 argument — instance. So i got an error:

File "/home/longman/workspace/youssr/youssr/../youssr/posting/views.py" in post_edit
  66.         form = EntryForm()

Exception Type: TypeError at /posts/write/
Exception Value: __init__() takes at least 2 arguments (1 given)

Change History (1)

in reply to:  description comment:1 by Thejaswi Puthraya, 16 years ago

Cc: thejaswi.puthraya@… added
Keywords: newforms added
Resolution: invalid
Status: newclosed

Replying to LongMan <alx.gsv@gmail.com>:
[snipped]

But, newforms/models.py

class BaseModelForm(BaseForm):
    def __init__(self, instance, data=None, files=None, auto_id='id_%s', prefix=None,
                 initial=None, error_class=ErrorList, label_suffix=':'):
        ...

I guess you are using an older version of svn pre r6915. The signature of the BaseModelForm's init was changed post r6915.
Here is the new signature.

def __init__(self, data=None, files=None, auto_id='id_%s', prefix=None, 
             initial=None, error_class=ErrorList, label_suffix=':', instance=None): 

Your ticket is invalid. There are no mistakes in the documentation and it works without even providing for an instance.

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