首页 > 解决方案 > 如何根据按钮对对象列表进行排序

问题描述

我是 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>

标签: djangosortingelement

解决方案


推荐阅读