分别对多个表进行排序

时间:2017-09-20 08:36:50

标签: python django sorting datatable

我有一个django模板,其中包含多个具有相同标题的表,我想分别对每个表进行排序。为此我使用 webstack-django-sorting https://github.com/webstack/webstack-django-sorting

当我单击我的示例中的标题时,它会对所有4个表进行排序,但我只想对一个表进行排序。

修改 哦对不起我复制了错误的代码! 我有4张不同内容的表格:

  • 生产中
  • 完成
  • 不匹配

有人能给我一个如何解决这个问题的提示吗?

{% extends 'base.html' %}

{% load sorting_tags %}

{% block body %}


<div class="container">
    <h1>Pending</h1>
    {% autosort articles_pending %}
    <table class="table">
        <thead>
            <tr>
                <th>{% anchor production_nr _("Production #") %}</th>
                <th>{% anchor article_nr _("Article #") %}</th>
                <th>{% anchor article_name _("Article name") %}</th>
                <th>{% anchor amount _("Amount") %}</th>
                <th>{% anchor price_offer _("Price") %}</th>
                <th>{% anchor create_date _("Create date") %}</th>
                <th>{% anchor start_date _("Target start date") %}</th>
                <th>{% anchor end_date _("Target end date") %}</th>
                <th>Status</th>
            </tr>
        </thead>
        <tbody>
            {% for articles_pending in articles_pending %}
            <tr>
                <td>{{ articles_pending.production_nr }}</td>
                <td>{{ articles_pending.article_nr }}</td>
                <td>{{ articles_pending.article_name }}</td>
                <td>{{ articles_pending.amount }}</td>
                <td>{{ articles_pending.price_offer|floatformat:2 }} €</td>
                <td>{{ articles_pending.create_date }}</td>
                <td>{{ articles_pending.start_date }}</td>
                <td>{{ articles_pending.end_date }}</td>
                <td>{{ articles_pending.status }}</td>
            </tr>
            {% endfor %}
        </tbody>
    </table>
     <h1>In production</h1>
    {% autosort articles_inproduction %}
    <table class="table">
        <thead>
              <tr>
                <th>{% anchor production_nr _("Production #") %}</th>
                <th>{% anchor article_nr _("Article #") %}</th>
                <th>{% anchor article_name _("Article name") %}</th>
                <th>{% anchor amount _("Amount") %}</th>
                <th>{% anchor price_offer _("Price") %}</th>
                <th>{% anchor create_date _("Create date") %}</th>
                <th>{% anchor start_date _("Target start date") %}</th>
                <th>{% anchor end_date _("Target end date") %}</th>
                <th>Status</th>
              </tr>
            </thead>
            <tbody>
              {% for articles_inproduction in articles_inproduction %}
                <tr>
                  <td>{{ articles_inproduction.production_nr }}</td>
                  <td>{{ articles_inproduction.article_nr }}</td>
                  <td>{{ articles_inproduction.article_name }}</td>
                  <td>{{ articles_inproduction.amount }}</td>
                  <td>{{ articles_inproduction.price_offer|floatformat:2 }} €</td>
                  <td>{{ articles_inproduction.create_date }}</td>
                  <td>{{ articles_inproduction.start_date }}</td>
                  <td>{{ articles_inproduction.end_date }}</td>
                  <td>{{ articles_inproduction.status }}</td>
                </tr>
              {% endfor %}
            </tbody>
    </table>
        <h1>Done</h1>
    {% autosort articles_done %}
    <table class="table">
        <thead>
              <tr>
                <th>{% anchor production_nr _("Production #") %}</th>
                <th>{% anchor article_nr _("Article #") %}</th>
                <th>{% anchor article_name _("Article name") %}</th>
                <th>{% anchor amount _("Amount") %}</th>
                <th>{% anchor price_offer _("Price") %}</th>
                <th>{% anchor create_date _("Create date") %}</th>
                <th>{% anchor start_date _("Target start date") %}</th>
                <th>{% anchor end_date _("Target end date") %}</th>
                <th>Status</th>
              </tr>
            </thead>
            <tbody>
              {% for articles_done in articles_done %}
                <tr>
                  <td>{{ articles_done.production_nr }}</td>
                  <td>{{ articles_done.article_nr }}</td>
                  <td>{{ articles_done.article_name }}</td>
                  <td>{{ articles_done.amount }}</td>
                  <td>{{ articles_done.price_offer|floatformat:2 }} €</td>
                  <td>{{ articles_done.create_date }}</td>
                  <td>{{ articles_done.start_date }}</td>
                  <td>{{ articles_done.end_date }}</td>
                  <td>{{ articles_done.status }}</td>
                </tr>
              {% endfor %}
            </tbody>
    </table>
     <h1>No match</h1>
    {% autosort articles_nomatch %}
    <table class="table">
        <thead>
              <tr>
                <th>{% anchor production_nr _("Production #") %}</th>
                <th>{% anchor article_nr _("Article #") %}</th>
                <th>{% anchor article_name _("Article name") %}</th>
                <th>{% anchor amount _("Amount") %}</th>
                <th>{% anchor price_offer _("Price") %}</th>
                <th>{% anchor create_date _("Create date") %}</th>
                <th>{% anchor start_date _("Target start date") %}</th>
                <th>{% anchor end_date _("Target end date") %}</th>
                <th>Status</th>
              </tr>
            </thead>
            <tbody>
              {% for articles_nomatch in articles_nomatch %}
                <tr>
                  <td>{{ articles_nomatch.production_nr }}</td>
                  <td>{{ articles_nomatch.article_nr }}</td>
                  <td>{{ articles_nomatch.article_name }}</td>
                  <td>{{ articles_nomatch.amount }}</td>
                  <td>
                      <form action="{% url 'change_price' order_id=articles_nomatch.pk article_id=articles_nomatch.article_id %}" method="post">{% csrf_token %}
                      <input type="number" name=new_price id="new_price" step="0.01" value="{{ articles_nomatch.price_offer|floatformat:2 }}" style="width: 5em;" />
                      <input class="btn btn-success myButton" type="submit" value="Save"/>
                      </form>
                  </td>
                  <!--<td>{{ articles_nomatch.price_offer|floatformat:2 }} € <a class="glyphicon glyphicon-edit"></a><a class="glyphicon glyphicon-ok"></a></td>-->
                  <td>{{ articles_nomatch.create_date }}</td>
                  <td>{{ articles_nomatch.start_date }}</td>
                  <td>{{ articles_nomatch.end_date }}</td>
                  <td>{{ articles_nomatch.status }}</td>
                </tr>
              {% endfor %}
            </tbody>
    </table>
</div>

{% endblock %}

0 个答案:

没有答案