Python Django循环模板,每15项新页面
现在我在一个计费应用程序中工作。我有一个定制设计的账单页面。该页面可包含15种产品。如果我打印的产品超过15个,这将覆盖到它们的页脚中。因此,如果超过15个产品,那么每15个项目创建一个新页面。我怎样才能做到这一点 我的看法Python Django循环模板,每15项新页面,python,django,Python,Django,现在我在一个计费应用程序中工作。我有一个定制设计的账单页面。该页面可包含15种产品。如果我打印的产品超过15个,这将覆盖到它们的页脚中。因此,如果超过15个产品,那么每15个项目创建一个新页面。我怎样才能做到这一点 我的看法 @login_required def print_sale(request,uuid): current_sale = Sales.objects.filter(uuid=uuid,deleted=0,shop_id = get_current_shop_
@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>
打印
{%load static%}
{%如果当前销售%}
{当前销售百分比中的销售百分比}
条例草案修订如下:
{{sale.customer.name}、{{sale.customer.email}、{{sale.customer.mobile}
{{sale.customer.address}
日期:{sale.sale_Date}
发票号:{{sale.id}
如果我理解正确,您可以使用。Django为
然而,最简单的方法是使用应用程序
设置后,您需要在模板中包括以下内容:
{# 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 %}
如果您希望有更好的经验来实现分页,您可以查看一下
Django无止境分页可用于提供Twitter风格或Digg风格的分页,并提供可选的Ajax支持和其他功能,如多重或惰性分页