django - 如何根据按钮对对象列表进行排序
问题描述
我是 Django 的新手,我想添加一种按钮,用于根据日期、降序和升序对元素进行排序。这个想法是在模板页面中添加一个按钮或轮播。并根据点击决定排序是升序还是降序。
我不知道如何将按钮链接到后端。
我知道查询集:
post.objects.order_by('date')
该按钮创建为:
<div class="form-group">
<label class="font-weight-light text-warning text-info " for="exampleFormControlSelect1" >Sort by date</label>
<select class="form-control" id="sort">
<option id="NtF">New to old</option>
<option id = "FtN">old to new</option>
</select>
解决方案
推荐阅读
- testing - 赛普拉斯 - 单击()后记录来自请求的响应数据
- swift - 断言失败UITableView:删除与另一个对象有关系的对象
- flutter - Flutter:目标 kernel_snapshot 失败
- typescript - 在打字稿中编写函数类型:胖箭头和对象字面量类型
- reactjs - 反应将状态从孩子传递给父母
- javascript - 无法使用 Jquery、Ajax、JSP 将自动完成搜索结果放入 HTML 表中
- python - VS Code Python Django 在开发容器中调试
- sccm - 如何在 SCCM 中导入设备
- javascript - 如何使用 componentDidCatch 处理多个错误边界组件
- functional-programming - idris 中隐式参数的顺序