2014-02-13 32 views
0

現在我正在結算應用程序。我有一個自定義設計的結算頁面。該頁面可以包含15個產品。如果我打印超過15種產品,則會覆蓋其頁腳。所以,如果超過15個產品,則每15個項目創建一個新頁面。我怎樣才能做到這一點。Django循環模板,每個15個項目的新頁面

我查看

@login_required  
def print_sale(request,uuid): 
    current_sale = Sales.objects.filter(uuid=uuid,deleted=0,shop_id = get_current_shop_id(request)).annotate(total=Sum('sale_products__subtotal'),total_received=Sum('sale_payment__amount')) 
    return render_to_response('sales/print.html',{'current_sale':current_sale},context_instance=RequestContext(request)) 

我的模板

<!DOCTYPE html> 
<html lang="en"> 
    <head> 
     <meta charset="utf-8" />   
     <title>print</title> 
     {% load static %} 
     <link rel="stylesheet" href="{% static 'css/print.css' %}" /> 
     <script type="text/javascript" src="{% static 'js/print.js' %}"></script> 
    </head> 
    <body> 
     <section class="wrapper"> 
      {%if current_sale %} 
       {% for sale in current_sale %} 
        <section id="top"> 
         <section id="bill_details" class="style1"> 
          <h2>Bill To :</h2> 
          <p> 
           {{ sale.customer.name }} , {{ sale.customer.email }} , {{sale.customer.mobile}} 
          </p> 
          <p class="address"> 
           {{ sale.customer.address }} 
          </p> 
         </section> 
         <div class="right"> 
          <p> 
           <b>Date <small>:</small></b>{{ sale.sale_date }} 
          </p> 
          <p> 
           <b>Invoice No<small>:</small></b> #{{ sale.id }} 
          </p> 
         </div> 
         <br class="clear" /> 
        </section>    
        <table> 
         <tr> 
          <th>Code</th> 
          <th>Name</th> 
         </tr> 
         {% for product in sale.sale_products_set.all %} 
         <tr class="parent"> 
          <td>{{ product.product.code }}</td> 
          <td>{{ product.product.name }}</td> 
         </tr> 
         {% endfor %} 
        </table> 
       {% endfor %} 
      {% endif %} 
     </section> 
    </body> 
</html> 

回答

1

Django提供支持pagination

然而,最簡單的方法是使用django-pagination應用。

一旦你設置它,這裏是你所需要的模板,包括:

{# At the top of the template #} 
{% load pagination_tags %} 
{% autopaginate sale.sale_products_set.all 15 %} 

{# Your normal template code here #} 

{# At the bottom, to show the pagination buttons #} 
{% paginate %} 
0

如果你想一些更好的實現與一些更好的體驗分頁,你可以看看到django endless pagination
的Django無盡的分頁可用於提供Twitter風格或Digg風格的分頁,可選的Ajax支持和其他功能,如多個或懶惰的分頁。