On Tue, 2012-01-10 at 23:49 -0800, coded kid wrote:
> Hi guys, whenever I signup for my django form, my database is only
> saving the id no and not names, username, email etc.     |  #sorry for
> posting it like this. I'm on mobile. Okay. In my views.py, this ( | )
> means next line.    @csrf_exempt
> | def welcome(request): | if request.method=='POST': |
> form=models.Register() |new_user=form.save() | return
> HttpResponseRedirect('/logpage/') | else: |form=models.Register()|
> return render_to_response('mainpage.html', {'form':models.Register}) .
> I created an html form and a model with class Register(models.Model):
> 
> names=models.CharField(max_length=50) etc. I hope you get my point?
> Please help.
> 

Your code isn't working because you are saving a model without passing
any attributes to it.

    form = model.Register()  # This isn't a form.  It's a model
    form.save()  

This will create an empty model, and then when you save it, try to write
that empty model to the database, which will work only if all the fields
are nullable, and will give you a model object with all fields null,
except the primary key, which is automatically populated.

Instead you need to do something like this:

     form = model.Register(names=request.POST['names'])
     form.save()

But really, you should use django's ModelForm, and let django do the
heavy lifting for you.  The django docs can get you started.


-- 
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.

Reply via email to