Hi Guys, I am unable to save to table TEST_QST ,it returns error QstForm object has no attribute 'save' I have confirmed that form.is_bound returns true form.is_valid returns true I have included my code in this post
Please asssit #MODEL ------------------------- class TEST_TYPE(models.Model): test_id = models.AutoField(max_length=3,primary_key=True) test_name = models.CharField(max_length=10, db_column='testname',unique=True) active = models.BooleanField(default = True,db_column='active') def __unicode__(self): return '%s' % self.test_id class TEST_CATEGORY(models.Model): test_cat_id = models.AutoField(max_length=3, db_column='testcatid', primary_key=True) test_id = models.ManyToManyField(TEST_TYPE,through='TEST_QST') test_cat_name = models.CharField(max_length=20, db_column='categoryname') active = models.BooleanField(default = True,db_column='active') def __unicode__(self): return '%s' % self.test_cat_id # def __unicode__(self): # return self.test_cat_name class TEST_QST(models.Model): qst_id = models.AutoField(max_length=8, primary_key=True) test_id = models.ForeignKey(TEST_TYPE) test_cat_id = models.ForeignKey(TEST_CATEGORY) qst = models.TextField() status = models.CharField(max_length='1',default='1') active = models.BooleanField(default = True) def __unicode__(self): return '%s' % self.qst_id #FORM ------------------------- from django.forms import ModelForm from django import newforms as forms from django.newforms import widgets from olewebapp.ole.models import TEST_QST,TEST_TYPE,TEST_CATEGORY # Create the form class. class QstForm(forms.Form): qst_id = forms.CharField(max_length=8,widget=forms.HiddenInput) test_id = forms.CharField(widget=forms.HiddenInput) test_cat_id =forms.CharField(widget=forms.HiddenInput) qst = forms.CharField (max_length='200',widget=forms.Textarea ,label='') status = forms.CharField(widget=forms.HiddenInput) active = forms.BooleanField(widget=forms.HiddenInput) class SaveQstForm(ModelForm): class Meta: model = TEST_QST #VIEW---------------------- if request.method == 'POST': if request.POST['submit_action'] == 'Add': # attempt to do add #QstForm = forms.form_for_model(TEST_QST) TId=TEST_TYPE.objects.get(test_id=request.POST['test_id']) CId=TEST_CATEGORY.objects.get(test_cat_id=request.POST ['test_cat_id']) form = QstForm() data = {'qst_id': request.POST['qst_id'], 'test_id':TId, 'test_cat_id': CId, 'qst': request.POST ['qst'], 'status': request.POST['status'] , 'active': request.POST['active'] } form = QstForm(data) try : if form.is_valid(): form.save(); message = 'Question added.' else: # validation failed: show submitted values in form message = 'Failed to added.' f = form except Exception, e: logging.error('%s Form error while saving--->' %form.errors ) logging.error('%s while saving---' % (e) ) 'QstForm' object has no attribute 'save' --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---