So CustomUser and UserDetails  is a model you made for your
users? If that is the case, you probably want to hook use a
modelform instead is it makes things a bit eaiser.

Anyways in your view, the user just pops out of the blue. My guess
is that you need to do something like user = CustomUser(...).
If your form is going to stay like it is now, only having 2 districts,
you
don't need AJAX, you can just make a javascript to onclick show the
districts. If you do want to make a javascript, you need to make a
view
for it, that you can post the state to. And then return some json that
you can act upon. The easiest thing is probably to make a dictionary
and then use simplejson to return it in json format. Just return it as
a
HttpRepsonse, as you just want the raw data. You can use the
request.is_ajax() to test if the request on the url is an ajax request
or some one trying to visit the page. That way you could use the
current
url as your ajax url if you want.

~Jakob

On 11 Maj, 08:36, newbie <mara.ku...@gmail.com> wrote:
> Hi,
>
>               I'm a newbie to Django. I have a form which has some
> attributes to be filled by the user viz., name, age, address etc. I
> want to get the address of the user by just allowing him making the
> selections rather than letting him fill it. I'm planning to give him a
> select box for state and then another select box giving the district
> in the country (which will be dynamically generated accessing the
> databased based on the selection made by the user). I've written a
> form for this purpose. But I dont know how to dynamically create them.
> Please help me out. Below is my code.
>
> In view:
>
> def register(request):
>         flash="Please enter your information in order to register"
>         form=regis()
>
>         if request.method == 'POST':
>                 form=regis(request.POST)
>
>                 username=request.POST.get('username', False)
>                 password=request.POST.get('password', False)
>                 password2=request.POST.get('password2', False)
>                 email=request.POST.get('email', False)
>                 user_type1=request.POST.get('user_type', False)
>                 mobile=request.POST.get('mobile', False)
>                 state=request.POST.get('state', False)
>                 district=request.POST.get('district', False)
>                 pincode=request.POST.get('pincode', False)
>                 address=request.POST.get('address', False)
>                 if password==password2:       CustomUser
> (mobile=mobile,username=username,password=password,email=email,user_type=user_type1)
>                         user.is_staff= 0
>                         user.save()
>                         userdetails=UserDetails
> (state=state,district=district,pincode=pincode,address=address,user=user)
>                         userdetails.save()
>                         flash="Thank You for Registering"
>                         message="You can start using our serices"
>                         return  HttpResponseRedirect('/default/
> index/')
>
>         return render_to_response('registerfran.html',locals())
>
> in forms.py:
> class regis(forms.Form):
>         state=(('Andhra Pradesh','andhra'),
> ('Maharastra','maharastra'))
>         district=(('Krishna','krishna'),('Guntur','guntur'))
>         username=forms.CharField(required=True)
>         password=forms.CharField(widget=forms.PasswordInput())
>         password2=forms.CharField(widget=forms.PasswordInput())
>         email=forms.CharField(required=True)
>         user_type=forms.ChoiceField(choices=(('Normal','normal'),
> ('Corporate','corporate'),('Franchise','franchise'),
> ('HeadOffice','headoffice')),required=False)
>         mobile=forms.CharField(required=True)
>         state=forms.ChoiceField(choices=state,required=False)
>         district=forms.ChoiceField(choices=district,required=False)
>         pincode=forms.CharField(required=True)
>         address=forms.CharField(widget=forms.Textarea(),required=True)
--~--~---------~--~----~------------~-------~--~----~
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