Thanks Actually earlier i was passing instance of Phone phoneform = PhoneForm(request.POST,instance=Phone.objects.get (user=request.user)) but at very first time there was no record in Phone table that is what i was getting the sql query is not matching so i tried with try: userob = Phone.objects.get(user=request.user) except Exception,e: userob = None if request.method == 'POST': phoneform = form_class(request.POST, instance=userob)
and its working fine: On Jan 30, 9:22 pm, cootetom <coote...@gmail.com> wrote: > You are created a PhoneForm but passing it an instance of User. You > need to pass the form an instance of the model it works on. > > - Tom > > On Jan 30, 3:45 pm, Praveen <praveen.python.pl...@gmail.com> wrote: > > > Hi > > > here is my views > > def phone_register(request, success_url=None,form_class = PhoneForm, > > template_name="phone/phonereg_form.html", > > extra_context=None): > > userobj = User.objects.get(pk=request.user.id) > > if request.method == 'POST': > > phoneform = form_class(request.POST, instance=userobj) > > if phoneform.is_valid(): > > phoneformobj = phoneform.save(commit=False) > > phoneformobj.user = request.user > > phoneformobj.mobile_key = random.randint(1000,10000) > > phoneformobj.save() > > # route_sms(smslane, phoneformobj.phoneno, Your Activation Key > > is: phoneformobj.mobile_key) > > return HttpResponseRedirect(success_url or reverse > > ('goto_dashboard')) > > else: > > phoneform = form_class(instance=userobj) > > if extra_context is None: > > extra_context = {} > > context = RequestContext(request) > > for key, value in extra_context.items(): > > context[key] = callable(value) and value() or value > > return render_to_response(template_name, > > {'phoneform':phoneform},context_instance=context) > > phone_register = login_required(phone_register) > > > Here is i have pasted the full codehttp://pastebin.com/m62209f51 -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.