Re: Issues with validation

2012-09-20 Thread Tom Evans
On Tue, Sep 18, 2012 at 11:12 AM, neeraj dhiman  wrote:
> I am using two models in my app and different form for each model, when I
> tried to validate these two forms , one model is validated but other is not.
>

You need to be a bit more selective about what code you show, and more
explicit about where the errors occur (or where the errors should
occur, whichever).

In your CustomerRegistration view, when initially rendering the forms
you construct a Registration_Form and a Check_Attribute_Form, but when
the form is resubmitted back to you, you only call is_valid() on the
Registration_Form instance. Therefore, validation never occurs on the
Check_Attribute_Form instance.

I've not looked at the other three views you posted along with
CustomerRegistration…

By the way, naming views with CamelCaps makes them look like classes
and isn't recommended.

Cheers

Tom

-- 
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: Issues with validation

2012-09-20 Thread Stephen Anto
Hi me too get the same problem... anyone help us..

On Tue, Sep 18, 2012 at 3:42 PM, neeraj dhiman  wrote:

> I am using two models in my app and different form for each model, when I
> tried to validate these two forms , one model is validated but other is not.
>
> model.py
>
> from django.db import models
> from django.contrib.auth.models import User
>
> class Customer(models.Model):
> user=models.OneToOneField(User)
> birthday=models.DateField()
> website=models.CharField(max_length=50)
> store=models.CharField(max_length=50)
> welcomemail=models.CharField(max_length=50)
>
>
>
>
>
>
> def __unicode__(self):
>  return self.user
>
> class Customer_check_attributes(models.Model):
> user=models.ManyToManyField(User)
> billing_add=models.CharField(max_length=50)
> shipping_add=models.CharField(max_length=50)
> payment_method=models.CharField(max_length=50)
> shipping_method=models.CharField(max_length=50)
> reward_points=models.CharField(max_length=50)
>
>
> form for first model **Customer**
>
> class Registration_Form(ModelForm):
>first_name  = forms.CharField(label=(u'First Name'))
>last_name   = forms.CharField(label=(u'Last Name'))
>username   = forms.CharField(label=(u'User Name'))
>email  = forms.EmailField(label=(u'Email Address'))
>password   = forms.CharField(label=(u'Password'),
> widget=forms.PasswordInput(render_value=False))
>
> :
>class Meta:
>   model=Customer
>
>   exclude=('user',)
>
> form for 2nd model **Customer_check_attributes**
>
> In template I am using this
> **for 1st model Customer** and it is validating the field first name
>
> 
> {% if form.first_name.errors %}{{
> form.first_name.errors }}{% endif %}
>  class="error"{% endif %}>Firstname:
> {{ form.first_name }}
> 
>
> **for 2nd model Customer_check_attributes** and it is not validating the
> field billing add
>
> 
> {% if check.billing_add.errors %}{{
> check.billing_add.errors }}{% endif %}
>  class="error"{% endif %}>Billing Address:
> {{ check.billing_add }}
> 
>
> here I am using **check** instead of form because I am storing the form in
> this and return it in context
>
>
> view.py
>
>
> from django.contrib.auth.models import User
> from customer_reg.models import Customer,Customer_check_attributes
> from django.http import HttpResponseRedirect
> from django.shortcuts import render_to_response
> from django.template import RequestContext
> from customer_reg.forms import Registration_Form,
> Check_Attribute_Form, LoginForm
> from django.contrib.auth import authenticate, login, logout
> from django.contrib.auth.decorators import login_required
>
>
> def CustomerRegistration(request):
> if request.user.is_authenticated():
> return HttpResponseRedirect('/profile/')
> if request.method == 'POST':
> form = Registration_Form(request.POST)
> if form.is_valid():
>
> user=User.objects.create_user(username=form.cleaned_data['username'],
> email=form.cleaned_data['email'], password = form.cleaned_data['password'])
> user.first_name = form.cleaned_data['first_name']
> user.last_name = form.cleaned_data['last_name']
> user.save()
>
> #customer=user.get_profile()
> #customer.birthday=form.cleaned_data['birthday']
> #customer.website=form.cleaned_data['website']
> #customer.store=form.cleaned_data['store']
> #customer.welcomemail=form.cleaned_data['welcomemail']
> #customer.save()
>
> customer=Customer(user=user,
> website=form.cleaned_data['website'],
> birthday=form.cleaned_data['birthday'], store=form.cleaned_data['store'],
> welcomemail=form.cleaned_data['welcomemail'])
> customer.save()
>
>   return HttpResponseRedirect('/profile/')
> else:
> check_form=Check_Attribute_Form()
> context={'form':form, 'check':check_form}
> return
> render_to_response('customer_register.html',context ,
> context_instance=RequestContext(request))
> else:
> ''' user is not submitting the form, show them a blank
> registration form '''
>
> form = Registration_Form()
> check_form = Check_Attribute_Form()
>  context={'form':form,'check':check_form}
>  return
> render_to_response('customer_register.html',context ,
> context_instance=RequestContext(request))
>
>
> #PROFILE#

Issues with validation of multiple forms

2012-09-18 Thread neeraj dhiman
I am using two models in my app and different form for each model, when I 
tried to validate these two forms , one model is validated but other is not.

model.py

from django.db import models
from django.contrib.auth.models import User

class Customer(models.Model):
user=models.OneToOneField(User)
birthday=models.DateField()
website=models.CharField(max_length=50)
store=models.CharField(max_length=50)
welcomemail=models.CharField(max_length=50)






def __unicode__(self):
 return self.user

class Customer_check_attributes(models.Model):
user=models.ManyToManyField(User)
billing_add=models.CharField(max_length=50)
shipping_add=models.CharField(max_length=50)
payment_method=models.CharField(max_length=50)
shipping_method=models.CharField(max_length=50)
reward_points=models.CharField(max_length=50)


form for first model **Customer**

class Registration_Form(ModelForm):
   first_name  = forms.CharField(label=(u'First Name'))
   last_name   = forms.CharField(label=(u'Last Name'))  
   username   = forms.CharField(label=(u'User Name'))
   email  = forms.EmailField(label=(u'Email Address'))
   password   = forms.CharField(label=(u'Password'), 
widget=forms.PasswordInput(render_value=False))

:   
   class Meta:
  model=Customer 
  
  exclude=('user',)

form for 2nd model **Customer_check_attributes**

In template I am using this 
**for 1st model Customer** and it is validating the field first name


{% if form.first_name.errors %}{{ 
form.first_name.errors }}{% endif %}
Firstname:
{{ form.first_name }}


**for 2nd model Customer_check_attributes** and it is not validating the 
field billing add


{% if check.billing_add.errors %}{{ 
check.billing_add.errors }}{% endif %}
Billing Address:
{{ check.billing_add }}


here I am using **check** instead of form because I am storing the form in 
this and return it in context 


view.py


from django.contrib.auth.models import User
from customer_reg.models import Customer,Customer_check_attributes
from django.http import HttpResponseRedirect
from django.shortcuts import render_to_response
from django.template import RequestContext
from customer_reg.forms import Registration_Form, Check_Attribute_Form, 
LoginForm
from django.contrib.auth import authenticate, login, logout
from django.contrib.auth.decorators import login_required


def CustomerRegistration(request):
if request.user.is_authenticated():
return HttpResponseRedirect('/profile/')
if request.method == 'POST':
form = Registration_Form(request.POST)
if form.is_valid():

user=User.objects.create_user(username=form.cleaned_data['username'], 
email=form.cleaned_data['email'], password = form.cleaned_data['password'])
user.first_name = form.cleaned_data['first_name']
user.last_name = form.cleaned_data['last_name']
user.save()

#customer=user.get_profile()
#customer.birthday=form.cleaned_data['birthday']
#customer.website=form.cleaned_data['website']
#customer.store=form.cleaned_data['store']
#customer.welcomemail=form.cleaned_data['welcomemail']
#customer.save()

customer=Customer(user=user, 
website=form.cleaned_data['website'], 
birthday=form.cleaned_data['birthday'], store=form.cleaned_data['store'], 
welcomemail=form.cleaned_data['welcomemail'])  
customer.save()

  return HttpResponseRedirect('/profile/')
else:
check_form=Check_Attribute_Form()
context={'form':form, 'check':check_form}
return 
render_to_response('customer_register.html',context , 
context_instance=RequestContext(request)) 
else:
''' user is not submitting the form, show them a blank 
registration form '''

form = Registration_Form()
check_form = Check_Attribute_Form()
 context={'form':form,'check':check_form}
 return render_to_response('customer_register.html',context 
, context_instance=RequestContext(request))


#PROFILE##

@login_required
def Profile(request):
 if not request.user.is_authenticated():
 return HttpResponseRedirect('/login/')
  #select = select * from auth_users
 #reg_users = User.objects.all()
 customer 

Issues with validation

2012-09-18 Thread neeraj dhiman
I am using two models in my app and different form for each model, when I 
tried to validate these two forms , one model is validated but other is not.

model.py

from django.db import models
from django.contrib.auth.models import User

class Customer(models.Model):
user=models.OneToOneField(User)
birthday=models.DateField()
website=models.CharField(max_length=50)
store=models.CharField(max_length=50)
welcomemail=models.CharField(max_length=50)






def __unicode__(self):
 return self.user

class Customer_check_attributes(models.Model):
user=models.ManyToManyField(User)
billing_add=models.CharField(max_length=50)
shipping_add=models.CharField(max_length=50)
payment_method=models.CharField(max_length=50)
shipping_method=models.CharField(max_length=50)
reward_points=models.CharField(max_length=50)


form for first model **Customer**

class Registration_Form(ModelForm):
   first_name  = forms.CharField(label=(u'First Name'))
   last_name   = forms.CharField(label=(u'Last Name'))  
   username   = forms.CharField(label=(u'User Name'))
   email  = forms.EmailField(label=(u'Email Address'))
   password   = forms.CharField(label=(u'Password'), 
widget=forms.PasswordInput(render_value=False))

:   
   class Meta:
  model=Customer 
  
  exclude=('user',)

form for 2nd model **Customer_check_attributes**

In template I am using this 
**for 1st model Customer** and it is validating the field first name


{% if form.first_name.errors %}{{ 
form.first_name.errors }}{% endif %}
Firstname:
{{ form.first_name }}


**for 2nd model Customer_check_attributes** and it is not validating the 
field billing add


{% if check.billing_add.errors %}{{ 
check.billing_add.errors }}{% endif %}
Billing Address:
{{ check.billing_add }}


here I am using **check** instead of form because I am storing the form in 
this and return it in context 


view.py


from django.contrib.auth.models import User
from customer_reg.models import Customer,Customer_check_attributes
from django.http import HttpResponseRedirect
from django.shortcuts import render_to_response
from django.template import RequestContext
from customer_reg.forms import Registration_Form, Check_Attribute_Form, 
LoginForm
from django.contrib.auth import authenticate, login, logout
from django.contrib.auth.decorators import login_required


def CustomerRegistration(request):
if request.user.is_authenticated():
return HttpResponseRedirect('/profile/')
if request.method == 'POST':
form = Registration_Form(request.POST)
if form.is_valid():

user=User.objects.create_user(username=form.cleaned_data['username'], 
email=form.cleaned_data['email'], password = form.cleaned_data['password'])
user.first_name = form.cleaned_data['first_name']
user.last_name = form.cleaned_data['last_name']
user.save()

#customer=user.get_profile()
#customer.birthday=form.cleaned_data['birthday']
#customer.website=form.cleaned_data['website']
#customer.store=form.cleaned_data['store']
#customer.welcomemail=form.cleaned_data['welcomemail']
#customer.save()

customer=Customer(user=user, 
website=form.cleaned_data['website'], 
birthday=form.cleaned_data['birthday'], store=form.cleaned_data['store'], 
welcomemail=form.cleaned_data['welcomemail'])  
customer.save()

  return HttpResponseRedirect('/profile/')
else:
check_form=Check_Attribute_Form()
context={'form':form, 'check':check_form}
return 
render_to_response('customer_register.html',context , 
context_instance=RequestContext(request)) 
else:
''' user is not submitting the form, show them a blank 
registration form '''

form = Registration_Form()
check_form = Check_Attribute_Form()
 context={'form':form,'check':check_form}
 return render_to_response('customer_register.html',context 
, context_instance=RequestContext(request))


#PROFILE##

@login_required
def Profile(request):
 if not request.user.is_authenticated():
 return HttpResponseRedirect('/login/')
  #select = select * from auth_users
 #reg_users = User.objects.all()
 customer