Code

Opened 7 years ago

Closed 7 years ago

#6328 closed (invalid)

ModelForm doc mistake?

Reported by: LongMan <alx.gsv@…> Owned by: nobody
Component: Documentation Version: master
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: UI/UX:

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)

Attachments (0)

Change History (1)

comment:1 in reply to: ↑ description Changed 7 years ago by thejaswi_puthraya

  • Cc thejaswi.puthraya@… added
  • Keywords newforms added
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to invalid
  • Status changed from new to closed

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.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.