我正在使用 django。
我的网页是这样工作的,如果我选中单选按钮并单击提交。它重定向到同一页面,并根据选中的单选按钮重新定义作业。我的问题是after loading the page none of the radio buttons are checked
。
我想检查在单击提交之前选中的单选按钮
代码
class MyHome(View):
filter_options=(
(('exp','Jobs by Experience'),
(['l1','Less Than 1 year',0],
['1b2','1 to 2 Years',0],
['2b3','2 to 3 Years',0],
['3b5','3 to 5 Years',0],)),
(('sal','Jobs by Salary'),
(['l1000','Less Than $1000',0],
['1000b3000','$1000 to $3000',0],
['3000b5000','$3000 to $5000',0])),
(('loc','Jobs by Location'),
(['che','Chennai',0],
['ban','Banglore',0])),
)
def get(self, request):
from django.db.models import Q
jobs=Job.objects.all().order_by("-postdate")
c_radio=[]
if 'exp' in request.GET:pass
if 'sal' in request.GET:
fl=request.GET['sal']
c_radio.append(fl)
if 'l' in fl:
#return HttpResponse(fl[1:])
q1=Q(basicpay__lte=fl[1:])
self.filter_options[1][1][0][2]=1
jobs=jobs.filter(q1)
elif 'b' in fl:
jobs=jobs.filter(basicpay__range=fl.split('b'))
self.filter_options[1][1][1][2]=1
if 'loc' in request.GET:
c_radio.append(request.GET["loc"])
jobs=jobs.filter(gmaplocation__district__icontains=request.GET["loc"])
#[2][1][1] ['ban', 'Banglore', 0]
return render(request,'job/jobs.html',{"jobs":jobs,'fopts':self.filter_options,'c_radio':c_radio})
html
{% for opts in fopts %}
<div class="accordion-group">
<div class="accordion-heading emp">
<a class="accordion-toggle collapsed" data-toggle="collapse" data-parent="#accordion" href="#collapse{{ forloop.counter }}"><!--item 1-->
{{ opts.0.1 }}
</a>
</div>
<div style="height: 0px;" id="collapse{{ forloop.counter }}" class="accordion-body collapse">
<div class="accordion-inner">
{% for opt in opts.1 %}
<label class="radio">
<input type="radio" name="{{ opts.0.0 }}" value="{{ opt.0 }}"{% ifequal opt.0.2 1 %} checked{% endifequal %}> {{ opt.1 }}{{ opt.0.2 }}
</label>
{% endfor %}
<!--<label class="checkbox">
<input type="checkbox" name="redefine"> Other
<input type="text" name="other">
</label>-->
</div>
</div>
</div><!--/accordion-group-->
{% endfor %}
更新:
这对我有用:
class RedefineChoices(forms.Form):
CHOICES_EXP=(('l1','Less Than 1 year'),
('1b2','1 to 2 Years'),
('2b3','2 to 3 Years'),
('3b5','3 to 5 Years'),
)
CHOICES_SAL=(('l1000','Less Than $1000'),
('1000b3000','$1000 to $3000'),
('3000b5000','$3000 to $5000'),
)
CHOICES_LOC=(('che','Chennai'),
('ban','Banglore'),)
exp = forms.ChoiceField(choices=CHOICES_EXP, widget=forms.RadioSelect(),label='Jobs by Experience')
sal = forms.ChoiceField(choices=CHOICES_SAL, widget=forms.RadioSelect(),label='Jobs by Salary')
loc = forms.ChoiceField(choices=CHOICES_LOC, widget=forms.RadioSelect(),label='Jobs by Location')enter code here