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__()
jsanchezs
  • 1,992
  • 3
  • 25
  • 51
Wagh
  • 4,202
  • 5
  • 39
  • 62

2 Answers2

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
Sunny Nanda
  • 2,362
  • 1
  • 16
  • 10
  • 1
    After this change, search `suggestion` in your code. Also, please paste the whole stacktrace of the error. – Sunny Nanda Feb 07 '14 at 06:19
  • Thanks for helping, The problem is solved,,,,,,,i write super(userInfoForm,self).__init__() instead of super(userInfoForm,self).__init__(*args, **kwargs) this. – Wagh Feb 07 '14 at 09:16
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