thxs, I have the Problem in accessing the values from the form.
On Feb 5, 11:13 am, Karen Tracey <kmtra...@gmail.com> wrote: > On Thu, Feb 5, 2009 at 12:55 AM, Neeru <neer...@gmail.com> wrote: > > > hi all, > > > As i'm new to the Django framework, > > i want to know the how can i insert the form data into the database. > > Plz.... let me know the solution and necessary changes that have to be > > done.... > > > program is like > > > --------------------------------------------------------------------------------- > > in models.py file code is as following: > > > class loan(models.Model): > > staffid = models.ForeignKey(employee) > > date = models.DateField() > > lamount = models.IntegerField(max_length=5) > > lsource = models.IntegerField(max_length=5) > > deductionrank = models.IntegerField(max_length=5) > > directpaymentto = models.CharField(max_length=30) > > totalloan = models.IntegerField(max_length=5) > > iamount = models.IntegerField(max_length=5) > > noofinstallments = models.IntegerField(max_length=5) > > finstallment = models.IntegerField(max_length=5) > > linstallment = models.IntegerField(max_length=5) > > > def __str__(self): > > return '%s' % (self.name) > > max_length implies you are using something post Django 0.96, so you probably > want a __unicode__ method, not a __str__ method. It'd help also if you > chose a field (or set of fields) to return that actually exists in the > model. > > > > > > > ---------------------------------------------------------------------------------- > > > In forms.py file > > > class loanform(forms.Form): > > staffid = forms.CharField(max_length=30) > > date = forms.DateField() > > lamount = forms.IntegerField() > > lsource = forms.IntegerField() > > deductionrank = forms.IntegerField() > > directpaymentto = forms.CharField(max_length=30) > > totalloan = forms.IntegerField() > > iamount = forms.IntegerField() > > noofinstallments = forms.IntegerField() > > finstallment = forms.IntegerField() > > linstallment = forms.IntegerField() > > I suggest you look into > ModelForms:http://docs.djangoproject.com/en/dev/topics/forms/modelforms/ > > > > > > > ----------------------------------------------------------------------------------- > > > In views.py file > > > def loanform(request): > > if request.method == 'POST': > > tr = loanform(request.POST) > > if tr.is_valid(): > > tr.save() > > return HttpResponseRedirect('/index') > > else: > > tr = loanform() > > return render_to_response('loan.html', {'form': tr}) > > > ------------------------------------------------------------------------------------ > > > in loan.html file > > > <html lang="en"> > > <head> > > <title>Test And Training record</title> > > </head> > > <body> > > <h2>Test And Training record</h2> > > > <form action="." method="POST"> > > <table> > > {{ form.as_table }} > > </table> > > <p> > > <input type="submit" value="Submit"></p> > > </form> > > </body> > > </html> > > > ------------------------------------------------------------------------------- > > > in urls.py file > > > (r'^loan', 'jewel.app.views.loanform'), > > > ------------------------------------------------------------------------------- > > > plz let me know as soon as possible.... > > thanks > > You've not said what goes wrong with what you've got. You might get better > responses if you put more effort into describing what your problem is, > exactly. > > Karen --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---