Drop-down dependency using Django and Python -
im still new in using django , python.. working on drop-down dependency in hwname , hwtype. tried many codes didn't worked.. here codes. please me :)
what want happen example in hwtype have flexi , flexi2, in hwname have female , male .. if choose flexi in hwtype, "female" display in hwname , if choose flexi2, hwname display "male" ..
models.py (codes)
class hwname(models.model): hwnid = models.autofield(max_length=6, primary_key=true, db_column='id') hwnname = models.charfield(max_length=255, db_column='name') class meta: db_table=u'hw_name' def __unicode__(self): return unicode((self.hwnname)) class hwtype(models.model): hwtid = models.autofield(max_length=6, primary_key=true, db_column='id') hwtname = models.charfield(max_length=255, db_column='name') class meta: db_table=u'hw_type' def __unicode__(self): return unicode((self.hwtname)) scbt inventory(advance search)
class inventory (models.model): id = models.autofield(max_length=6, primary_key=true, db_column='id') hwname = models.foreignkey(hwname, db_column='hw_name', default=1) hwtype = models.foreignkey(hwtype, db_column='hw_type', default=1) class meta: db_table=u'inventory' def __unicode__ (self): return unicode((self.assetnumber, self.serialnumber, self.hwname, self.hwtype)) advanced search hardware form
class advancedsearchform (modelform): hwname = forms.modelchoicefield(queryset=hwname.objects.all(), label="hardware name") hwtype = forms.modelchoicefield(queryset=hwtype.objects.all(), label="hardware type") class meta: model = inventory exclude = ('id', 'assetnumber', 'serialnumber', 'remarks') views.py (codes)
def inventory (request): ##advanced search form:## form = advancedsearchform(request.post or none) ##check if form not empty## hwname = request.get.get('hwname', 0) hwtype = request.get.get('hwtype',0) if hwname == 'none': hwname = '' if hwtype == 'none': hwtype = ''
try "django-smart-selects"
looks need
https://github.com/digi604/django-smart-selects
Comments
Post a Comment