Getting __init__() got an unexpected keyword argument 'instance' with CreateView of Django -


some details:

request method: request url: http://localhost:8080/user/create django version: 1.5.1 exception type: typeerror exception value: ____init____() got unexpected keyword argument 'instance' exception location: /place/venv/local/lib/python2.7/site-packages/django/views/generic/edit.py in get_form, line 35 python executable: /place/venv/bin/python python version: 2.7.3 

views.py

class usercreateview(createview):     model = models.user     form_class = forms.userform 

urls.py

url(r'^user/create$', usercreateview.as_view(), name='user_create'), 

forms.py

class userform(forms.form):     group_choices = [(-1, '[choose]')]     group_choices += [(group.id, group.name.capitalize()) group in auth.models.group.objects.all()]      email = forms.emailfield(         label='email',         widget=forms.textinput(attrs={'placeholder': 'email'})     )     first_name = forms.charfield(         label='first name',         widget=forms.textinput(attrs={'placeholder': 'first name'})     )     last_name = forms.charfield(         label='last name',         widget=forms.textinput(attrs={'placeholder': 'last name'})     )     password = forms.charfield(         label='password',         widget=forms.passwordinput(attrs={'placeholder': 'password'})     )     password_validation = forms.charfield(         label='repeat password',         widget=forms.passwordinput(attrs={'placeholder': 'repeat password'})     )     mobile_number = forms.charfield(         label='mobile number',         widget=forms.textinput(attrs={'placeholder': 'mobile number'})     )     office_number = forms.charfield(         label='office number',         widget=forms.textinput(attrs={'placeholder': 'office number'})     )     group = forms.choicefield(         label='group',         choices=group_choices     )      def clean_password_validation(self):         if self.cleaned_data['password'] == self.cleaned_data['password_validation']:             return self.cleaned_data['password_validation']         else:             raise forms.validationerror('passwords don\'t match')      def clean_group(self):         if self.cleaned_data['group'] != -1:             return self.cleaned_data['group']         else:             raise forms.validationerror('please, choose group') 

models.py

class user(models.model):     user = models.onetoonefield(auth.models.user)     mobile_number = models.charfield(max_length=64)     office_number = models.charfield(max_length=64) 

i suspect class userform should model form. may want change fields, should derived `modelform.

so change form definition to

class userform(forms.modelform):    class meta:        model = user        fields = [...] # list of fields want model     #or define fields want.    .... 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -