在Django中一次将多个商品添加到购物车

是否有可能知道用户根据html类更改在django模型中选择了哪个项目?

我有一个Django模型中的数据,该数据以表格的形式呈现给用户,用户需要从列表中选择他们想购买的项目,然后结帐。他们将选择所有想要的项目,然后提交,而不是像传统的“添加到购物车”系统那样一一提交。

我有Jquery,它允许我切换表中每一行的html类,该类选择并突出显示单击时的行,但是我不知道如何将类中的更改转换为django可以用来实现的功能标识已显示的哪些项目已被选择添加到购物车。

JQuery

$("body").on('click','#food_table tbody tr',function() {
$(this).toggleclass("highlight");
});

HTML以显示表格并突出显示班级

<style media="screen">
  .highlight {
    background-color: yellow;
    color: white;
    }
</style>

......

     <table class="table table table-borderless" id="food_table">
        <thead>
          <tr>
            <th>ID</th>
            <th>Description</th>
            <th>Price</th>
          </tr>
        </thead>
        <tbody>
          {% for order in orders %}
          <tr>
            <td>{{ item.pk }}</td>
            <td>{{ item.Price }}</td>
            <td>{{ item.Description }}</td>
          </tr>
          {% endfor %}
        </tbody>
      </table>

一旦某一行具有“ highlight”类,是否可以将该行中的项目的PK返回django,这样我就可以知道用户在数据库中选择了哪些项目?

预先感谢

qe2004 回答:在Django中一次将多个商品添加到购物车

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3162769.html

大家都在问