Re: Please help me with django form 2.

2012-01-11 Thread J. Cliff Dyer


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.



Re: Please help me with django form 2.

2012-01-11 Thread 软刀
as I unflod your code
I think may be you should create a Form-class like this:
class RegisterForm(ModelForm):
class Meta:
model = Register


and in your view should be:
@csrf_exempt
def welcome(request):
if request.method=='POST':
form=RegisterForm(request.POST)
new_user=form.save()
return HttpResponseRedirect('/logpage/')
else:
form=RegisterForm()
return render_to_response('mainpage.html', {'form':form})


-- 
as I learning english, any help about english grammar is welcome

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



Re: Please help me with django form 2.

2012-01-11 Thread kenneth gonsalves
On Tue, 2012-01-10 at 23:49 -0800, coded kid wrote:
> names=models.CharField(max_length=50) etc. I hope you get my point?
> Please help. 

I would suggest that you get to a computer and post the full code.
Please help us to help you.
-- 
regards
Kenneth Gonsalves

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



Please help me with django form 2.

2012-01-10 Thread coded kid
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.

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