我想在模板中设置过滤器
我已经过滤了我想要的对象,现在我该如何设置模板?
所以我可以通过下拉列表过滤对象吗?
到目前为止我做了什么
@login_required
def list_jobs(request):
assigned_jobs = Job.objects.filter(assign_to=request.user).order_by('-date_created')
created_jobs = Job.objects.filter(user=request.user).order_by('-date_created')
completed_jobs = Job.objects.filter(completed=False).order_by('-date_completed')
return render(request, 'jobs/list.html', {'created_jobs': created_jobs, 'assigned_jobs': assigned_jobs,
'completed_jobs': completed_jobs})
答案 0 :(得分:3)
示例像这样:
<select id="id">
{% for i in assigned_jobs %}
<option value="{{ i.id }}">{{ i.name }}</option>
{% endfor %}
</select>