0

ビューにページネーションを追加しました。ページネーションは正常に機能していますが、データをフィルタリングして次のページに移動すると、フィルタリングされたデータをページネーションしていないため、フィルタリングが行われていない次のページに移動します。

views

 class CashFilter(django_filters.FilterSet):

    class Meta:
        model = NSE_Cash_Trades
        fields = {'dates':['lte','gte'],'order_entry_time':['lte','gte'],'trade_entry_time':['lte','gte'],'trade_modified_time':['lte','gte'],'symbol':['exact'],'client_ac':['exact'],'buys_sell_indicator':['exact'],'participant_code':['exact'],'trade_qty':['exact'],'ctcls_id':['exact'],'order_num':['exact'],'trade_no':['exact']}


 def NSE_Cash_Trades_Search(request):
      f =CashFilter(request.GET, queryset=NSE_Cash_Trades.objects.all())
      paginator = Paginator(f.qs,100)
      page = request.GET.get('page')
      try:
         leads = paginator.page(page)
      except PageNotAnInteger:

         leads = paginator.page(1)
      except EmptyPage:

         leads = paginator.page(paginator.num_pages)

      t = loader.get_template('admin/newftp/search2.html')
      ctx=RequestContext(request,{'filter':f,"leads":leads,})
        return HttpResponse(t.render(ctx))`

template

{% extends "admin/newftp/change_list.html" %}
{% block content %}
<h2><a href="/admin/newftp/nse_cash_trades?status=">Back to Nse Cash trade page</a></h2>
<form action="" method="get">
<!--Required for dynamic total of a column based on search filter
{% for k,v in result1.items %}
<input type="text" name="result1" value="{{ v }}"/>
{% endfor %}
input type="button" name="result1" value= "Total Value" 
-->
  {{ filter.form.as_p }}<br>
  <input type="submit" />
</form>
<div class="pagination">
    <table border="1">

  <tr>
  <th>Sr.No.</th>
  <th>Trade date</th>
  <th>Symbol </th>
  <th>Client Code </th>
  <th>Buy/Sell </th>
  <th>Participant Code</th>
  <th>Trade qty </th>
  <th>CTCL ID</th>
  <th>Order Number</th>
  <th>Trade no </th>
  <th>Order Entry Date Time</th>
  <th>Trade Entry Dt Time</th>
  <th>Trade modified time</th>
  <th>Trade Price</th> 
  <th>Trade Status</th>
  <th>Series</th>
  <th>Security Name</th>
  <th>Instrument Type</th>
  <th>Book Type</th>
  <th>Market Type</th>
  <th>User ID</th>
  <th>Branch ID</th>
  <th>Pro/Cli</th>
  <th>Auction Part Type</th>
  <th>Auction NO</th>
  <th>Sett Period</th>
  <th>Counter Party Id</th>
  </tr>

    {% for line in leads %} 
    <tr>
      <td>{{ forloop.counter}}</td>
      <td>{{ line.dates|date:"d/m/Y"}}</td>
      <td>{{ line.symbol}}</td>
      <td>{{ line.client_ac}} </td>
      <td>{{ line.buys_sell_indicator}}</td>
      <td>{{ line.participant_code}}</td>
      <td>{{ line.trade_qty}}</td>
      <td>{{ line.ctcls_id}}</td>
      <td>{{ line.order_num}}</td>
      <td>{{ line.trade_no}}</td>
      <td>{{ line.order_entry_time|date:"d/m/Y h:m:s"}}</td>
      <td>{{ line.trade_entry_time|date:"d/m/Y h:m:s" }}</td>
      <td>{{ line.trade_modified_time|date:"d/m/Y h:m:s" }}</td>
      <td>{{ line.trade_price }}</td>
      <td>{{ line.trades_status }}</td>
      <td>{{ line.series }}</td>
      <td>{{ line.security_name }}</td>
      <td>{{ line.instruments_type }}</td>
      <td>{{ line.books_type }}</td>
      <td>{{ line.markets_type }}</td>
      <td>{{ line.user_id }}</td>
      <td>{{ line.branchs_id }}</td>
      <td>{{ line.pros_cli }}</td>
      <td>{{ line.auctions_part_type}}</td>
      <td>{{ line.auction_num }}</td>
      <td>{{ line.sett_period }}</td>
      <td>{{ line.counter_party_id }}</td>
      </tr>
      {% endfor %}
</table>
  <span class="step-links">
    {% if leads.has_previous %}
    <a href="?page={{ leads.previous_page_number }}">previous</a>
    {% endif %}

    <span class="current">
      Page {{ leads.number }} of {{ leads.paginator.num_pages }}.
    </span>

    {% if leads.has_next %}
    <a href="?page={{ leads.next_page_number }}">next</a>
        {% endif %}
  </span>
</div>
{% endblock %}

誰でも解決策を見つけるのを手伝ってもらえますか?

4

2 に答える 2

0

テンプレートで以下に示す変更を行ってください。以下のコードにより、ページネーションがフィルタリングされた値を取得できるようになり、フィルタリングされた値を介してページネーションされます。次に同じ変更を行います

</table>
  <span class="step-links">
    {% if leads.has_previous %}
    <a href="?page={{ leads.previous_page_number }}&dates__lte={{request.GET.dates__lte}}&dates__gte={{request.GET.dates__gte}}&order_entry_time__lte={{request.GET.order_entry_time__lte}}&order_entry_time__gte={{request.GET.order_entry_time__gte}}&trade_entry_time__te={{request.GET.trade_entry_time__lte}}&trade_entry_time__gte={{request.GET.trade_entry_time__gte}}&trade_modified_time__lte={{request.GET.trade_modified_time__lte}}&trade_modified_time__gte={{request.GET.trade_modified_time__gte}}&symbol={{request.GET.symbol}}&client_ac={{request.GET.client_ac}}&buys_sell_indicator={{request.GET.buys_sell_indicator}}&participant_code={{request.GET.participant_code}}&trade_qty={{request.GET.trade_qty}}&ctcls_id={{request.GET.ctcls_id}}&order_num={{request.GET.order_num}}&trade_no={{request.GET.trade_no}}">previous</a>
于 2015-03-17T09:41:54.253 に答える
0

ここであなたがしなければならないことは、リクエスト値をURLに渡すことです。以下のようにテンプレートを変更する必要があります

</table>
  <span class="step-links">
    {% if leads.has_previous %}
    <a href="?page={{ leads.previous_page_number }}&dates__lte={{request.GET.dates__lte}}&dates__gte={{request.GET.dates__gte}}&order_entry_time__lte={{request.GET.order_entry_time__lte}}&order_entry_time__gte={{request.GET.order_entry_time__gte}}&trade_entry_time__te={{request.GET.trade_entry_time__lte}}&trade_entry_time__gte={{request.GET.trade_entry_time__gte}}&trade_modified_time__lte={{request.GET.trade_modified_time__lte}}&trade_modified_time__gte={{request.GET.trade_modified_time__gte}}&symbol={{request.GET.symbol}}&client_ac={{request.GET.client_ac}}&buys_sell_indicator={{request.GET.buys_sell_indicator}}&participant_code={{request.GET.participant_code}}&trade_qty={{request.GET.trade_qty}}&ctcls_id={{request.GET.ctcls_id}}&order_num={{request.GET.order_num}}&trade_no={{request.GET.trade_no}}">previous</a>
    {% endif %}

href next に同じ変更を加えます

于 2015-03-17T09:36:40.670 に答える