Hi me too get the same problem... anyone help us..

On Tue, Sep 18, 2012 at 3:42 PM, neeraj dhiman <ndhima...@gmail.com> 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
>
>     <div class="register_div">
>         {% if form.first_name.errors %}<p class="error">{{
> form.first_name.errors }}</p>{% endif %}
>         <p><label for="first_name" {% if form.first_name.errors %}
> class="error"{% endif %}>Firstname:</label></p>
>         <p>{{ form.first_name }}</p>
>     </div>
>
> **for 2nd model Customer_check_attributes** and it is not validating the
> field billing add
>
>     <div class="register_div">
>             {% if check.billing_add.errors %}<p class="error">{{
> check.billing_add.errors }}</p>{% endif %}
>         <p><label for="billing_add" {% if check.billing_add.errors %}
> class="error"{% endif %}>Billing Address:</label></p>
>         <p>{{ check.billing_add }}</p>
>     </div>
>
> 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 = request.user.get_profile
>          context = {'customer':customer}
>          return render_to_response('sucess.html',context,
> context_instance=RequestContext(request))
>
>
>
> ##########################################LOGIN########################################
>
>
>     def LoginRequest(request):
>          if request.user.is_authenticated():
>              return HttpResponseRedirect('/profile/')
>          if request.method == 'POST':
>              form = LoginForm(request.POST)
>              if form.is_valid():
>                      username = form.cleaned_data['username']
>                      password = form.cleaned_data['password']
>                      customer = authenticate(username=username,
> password=password)
>                      if customer is not None:
>                          login(request, customer)
>                          return HttpResponseRedirect('/profile/')
>                      else:
>                          return
> render_to_response('login1.html',{'form':form} ,
> context_instance=RequestContext(request))
>              else:
>                      return render_to_response('login1.html',{'form':form}
> , context_instance=RequestContext(request))
>
>          else:
>              ''' user is not submitting the form, show the login form '''
>              form = LoginForm()
>              context={'form':form}
>              return render_to_response('login1.html',{'form':form} ,
> context_instance=RequestContext(request))
>
>
>     #######################################checkout
> attributes##################################################
>
>
>     def Checkout_Attributes(request):
>
>
>         #try:
>            #user_profile = Customer.objects.get(user=request.user)
>         #except Customer.DoesNotExist:
>            # this user has no profile
>           # return render_to_response('error')
>         #user_profile_form = Check_Attribute_Form(instance=user_profile)
>         #return
> render_to_response('checkout.html',{'form':user_profile_form},context_instance=RequestContext(request))
>
>         check_form = Check_Attribute_Form()
>         context={'form':check_form}
>         return
> render_to_response('checkout.html',context,context_instance=RequestContext(request))
>
>     def Set_Checkout_Attributes(request):
>
>         #if request.user.is_authenticated():
>             #return HttpResponseRedirect('/checkout/')
>
>         if request.method == 'POST':
>             check_form = Check_Attribute_Form(request.POST)
>                 if check_form.is_valid():
>
> customer_check=Customer_check_attributes(billing_add=check_form.cleaned_data['billing_add'],shipping_add=check_form['shipping_add'],payment_method=check_form['payment_method'],shipping_method=check_form['shipping_method'],reward_points=check_form['reward_points'])
>                 customer_check.save()
>                           return HttpResponseRedirect('/profile/')
>             else:
>                 check_form=Check_Attribute_Form()
>                 return
> render_to_response('a.html',{'check_form':check_form} ,
> context_instance=RequestContext(request))
>         else:
>                 return render_to_response('f')
>
>
>
>
> ###############################################Logout#############################################################
>
>     def LogoutRequest(request):
>          logout(request)
>          return HttpResponseRedirect('/login/')
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/GZiIdf2PyyoJ.
> 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.
>



-- 
Thanks & Regards
Stephen S



Website: www.f2finterview.com
Blog:      blog.f2finterview.com
Tutorial:  tutorial.f2finterview.com
Group:    www.charvigroups.com

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