二级联动用ajax还是很好实现的,下面简单给个例子
jquery代码
$("#id_sel").change(function(){ $.get("/browser/gettestcase?type="+cate, function(result){ //$(".form-control-select").find('[value=header]').remove(); //$(".form-control-select").selectpicker('refresh'); if(result.length > 0) { $.each(result,function(index,value){ $(".form-control-select").append("<option value='"+value.label+"'>"+value.text+"</option>"); }) } } )})
django代码
def gettestcase(request): options_list = [] cate = request.GET.get('type', 'shop') print cate options = TestCase.objects.filter(case_category=cate) for case in options: c = {} c['label'] = case.case_name c['text'] = case.case_name options_list.append(c) return HttpResponse(json.dumps(options_list), content_type='application/json')