0

I am trying to save the data in database using Python-Django. But i am getting this error:

'userInfo' object has no attribute 'suggestion' 

This is my model.py file model.py

class userInfo(models.Model): #user = models.ForeignKey(User) #age = models.IntegerField() u_name=models.TextField("Name", null = True, blank = True) u_address=models.TextField("Address", null = True, blank = True) def __unicode__(self): return self.u_name 

This is my view.py file
view.py

 def gaurav(request): print request form=userInfoForm() if request.POST: form = userInfoForm(request.POST) anw=form.save(commit=False) anw.user=request.user anw.save() form= userInfoForm(request.POST) if form.is_valid(): user1=form.save() return render(request, 'userview/home.html', {'form': form}) 

This is my form.py file
form.py

 class userInfoForm(forms.ModelForm): class Meta: model = userInfo def __init__(self, *args, **kwargs): super(userInfoForm,self).__init__() 
1
  • I suggest not editing a question to be correct, instead mark the answer as correct Commented Jan 6, 2017 at 10:09

2 Answers 2

3

Inside the__unicode__ method of userInfo, you are trying to use self.suggestion but suggestion is not defined in the model fields.

Try using another attribute:

class userInfo(models.Model): # Model fields.. def __unicode__(self): return self.u_name 
Sign up to request clarification or add additional context in comments.

2 Comments

After this change, search suggestion in your code. Also, please paste the whole stacktrace of the error.
Thanks for helping, The problem is solved,,,,,,,i write super(userInfoForm,self).__init__() instead of super(userInfoForm,self).__init__(*args, **kwargs) this.
0

If you have changed the code as @Sunny Nanda Mentioned and still getting the same error, then try cleaning the .pyc files of that project and reload the dev server

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.