python - Implementing dynamic dropdown menu in django -
i want create dynamic drop-down menu car details
so created 4 models models.py
class companymake(models.model): company_name = models.charfield(max_length = 100) def __unicode__(self): return self.company_name class makemodel(models.model): company = models.foreignkey(companymake) model_name = models.charfield(max_length = 100) def __unicode__(self): return self.model_name class modelparts(models.model): company = models.foreignkey(companymake) model = models.foreignkey(makemodel) part_name = models.charfield(max_length = 100) def __unicode__(self): return self.part_name class modelyear(models.model): company = models.foreignkey(companymake) model = models.foreignkey(makemodel) year_value = models.integerfield() class userprofile(models.model): user = models.onetoonefield(user,primary_key=true) #image = models.imagefield(upload_to=get_photo_storage_path, null = true, blank=true) part = models.foreignkey(modelparts,null = true, blank=true) phone_number = models.charfield( max_length = 10,verbose_name="mobile number 10 digits",null = true, blank=true, default=none)
now want create drop-down menu car, model, part , year if particular car selected models related car should in next model drop-down, if particular drop-down selected parts related model should in next part drop-down menu same year.
my views.py
def home(request): cm = companymake.objects.all() in cm: print mm = a.makemodel_set.all() b in mm: print b mp = b.modelparts_set.all() c in mp: print c = modelyear.objects.all() print return render(request,'choice.html',{'cm':cm,'mm':mm, 'mp':mp, 'my':my})
my choice.html file is
<select name="car"> {% car in cm %} <option value="{{car.key}}" selected="selected">{{car.company_name}}</option> {% endfor %} </select> <br/>
please guide me in right direction. getting car models drop-down menu. in above way can drop-down menu not related each other. want drop-down menu in related order. car related models should there, models related parts should there.
Comments
Post a Comment