我想创建一个过滤器框,我可以在其中过滤对象列表:
**models.py**
class Personal(models.Model):
first_name = models.CharField(max_length=128)
last_name = models.CharField(max_length=128)
email = models.EmailField()
age = models.DateField(null=True)
non_veg = models.BooleanField(default=False)
alcohol = models.BooleanField(default=False)
pure_veg = models.BooleanField(default=False)
**forms.py**
class PersonForm(forms.ModelForm):
class Meta:
model = Personal
fields = ['first_name', 'last_name', 'email', 'age', 'non-veg', 'alcohol', 'pure_veg']
**views.py**
def my_personal(request):
my_data = Personal.objects.all()
return render(request, "personal.html", data)
**personal.html**
<body>
<div id="filter_list">
<h3>Filter By</h3>
<h4>Age</h4>
<select>
<option value="1"> From 18 to 20 years</option>
<option value="2"> From 21 to 25 years</option>
<option value="3"> From 26 to 30 years</option>
<option value="4"> From 31 to 35 years</option>
<option value="5"> From 36 to 40 years</option>
<option value="6"> Above 40 years</option>
</select>
<h4>Likes</h4>
<input type="checkbox" name="non_veg"> Non-Veg Food
<input type="checkbox" name="alcohol"> Alcohol
<input type="checkbox" name="pet_allowed"> Pure Veg
<input type="submit" name="submit" value="Apply filters">
</body>
通过上面的例子,如果我选择年龄18到20岁并勾选非蔬菜食品复选框并点击应用过滤器,它应该显示喜欢非蔬菜的人,年龄限制为18至20岁相同页面。
答案 0 :(得分:0)
DECLARE
@DateRangeStart [DATETIME2](7),
@DateRangeEnd [DATETIME2](7),
@TenantID [SMALLINT] ,
@ActivityContextID [INT],
@StudentID [INT] = NULL
DECLARE @Query VARCHAR(8000)
SET @Query='select count(s.ID),count(distinct(s.ID)) from SimulationVisit SV inner join Student s on s.ID=SV.StudentID
inner join ActivityContext AC on AC.ID=SV.ActivityContextID
WHERE (AC.TenantID = '+CAST(@TenantID AS VARCHAR(10))+' OR @TenantID is null)
AND (AC.ID =' +CAST(@ActivityContextID AS VARCHAR(10))+')
AND (SV.StudentID = '+CAST(@StudentID AS VARCHAR(10))+')'
EXEC(@Query)
你传递的背景错误了。你必须在这里有一个错误返回渲染(请求,&#34; personal.html&#34;,数据),因为没有这样的东西数据。