1

I want to make a view to user such that number of dropdowns can be increased.How can this be done?

Features: If we click a + button one more extra dropdown gets added. Also the values of all dropdown are not same they have to change dynamically.What I mean is If suppose first dropdown is a country and second dropdown is a state then upon selecting country states should change.

my models.py

from django.db import models
from django.forms import ModelForm
from smart_selects.db_fields import GroupedForeignKey
MUMBAI='mumbai'
CHENNAI='chennai'
BANGALORE='bangalore'
HYDERABAD='hyderabad'


CHOICES1 = 
    (
    (MUMBAI,'mumbai'),
    (CHENNAI,'chennai'),
    (BANGALORE,'bangalore'),
    (HYDERABAD,'hyderabad'),
     )
class House(models.Model):
    choice_field = models.CharField(max_length=200,choices=CHOICES1)

class EmailAddress(models.Model):
    email = models.ForeignKey(House)
    house = GroupedForeignKey(House, 'email_addresses')
class SampleForum(ModelForm):
    class Meta:
        model=EmailAddress
        fields=['house','email']

my forms.py

from django import forms
from draft.models import EmailAddress
MUMBAI='mumbai'
CHENNAI='chennai'
BANGALORE='bangalore'
HYDERABAD='hyderabad'


CHOICES1 = (
        (MUMBAI,'mumbai'),
        (CHENNAI,'chennai'),
        (BANGALORE,'bangalore'),
        (HYDERABAD,'hyderabad'),
           )

class SampleHouse(forms.Form):
    choice_field = forms.ChoiceField(choices=CHOICES1)

class SampleForum(forms.Form):
    class Meta:
        model=EmailAddress
        fields='__all__'

What I tried

I tried to create variable fields in a class of model.So that each field has to have different value. Django models with variable number of fields

https://github.com/digi604/django-smart-selects I tried this to make the values of dropdown change dynamically but I am not even getting display of values

The result I want should be like this

https://www.dropbox.com/s/hxw3yfi9r4dswbw/Screen%20Shot%202014-06-05%20at%2012.40.33%20pm.png

I just want to know what fields to use and any js/jquery django app if possible for adding multiple dropdowns

Community
  • 1
  • 1
iLoveCamelCase
  • 450
  • 10
  • 21

0 Answers0