Print for loop data based on the item quantity given in django
Let us consider purchase_order_id = 199
for this purchase_order we are having 2 items (let us consider item_names as Samsung Note 3(item 1),Ear capsule(item 2))
Now item_1(Samsung Note 3) quantity is given as 2 and item_2(,Ear capsule) quantity is given as 3
now in the pdf how i need to print the labels is item_1 2 times as quantity is 2 and item_2 as 3 times as quantity is 3
Let us consider my views.py as
class PrintLabels(View):
def get(self, request, id, value):
client = request.user.client
order = OtherOrder.objects.get(client=client, id=id)
items = order.otherorderitem_set.all()
items_list = []
for c in items:
item_dict = {}
if c.batch_number:
item_dict['batch_number'] = c.batch_number
if c.due_date:
item_dict['due_date'] = c.due_date
if c.season_support:
item_dict['season_support'] = c.season_support
if c.flower_colour:
item_dict['flower_colour'] = c.flower_colour
....
....
....
items_list.append(item_dict)
template = loader.get_template('po_labels.django.html')
context_dict = {
'items_list' : items_list,
'items' : items,
'order' : order,
}
context = Context(context_dict)
html = template.render(context)
result = StringIO.StringIO()
pdfkit.from_string(html, 'applicationpdf.pdf')
pdf = open("applicationpdf.pdf")
response = HttpResponse(pdf.read(), content_type='application/pdf')
return response
let us consider my template.html as
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Light Degree</title>
{% load i18n crm_tags sekizai_tags widget_tweaks %}
<style>
html
{
background-color:#f4f4f4;
}
body
{
margin:0px;
}
@media print { @page { margin: 0; } body { margin: 0cm; } }
</style>
</head>
<body>
<!--Main Label 216-->
<div class="">
{% for item in items_list %}
{% if item.tree_type != 'Hedging' %}
<div>
<div style="width:50%; float:left;">
<div class="main_label" style="width:367px; height:211px;">
<table border="0" cellspacing="0" cellpadding="0" style="width:367px; height:211px; background-color:#ffffff; border-radius:12px;">
<tr>
<td style="width:6px;"> </td>
<td style="height: 211px; width: 351px; vertical-align: middle;">
<table width="100%" border="0" cellspacing="0" cellpadding="0" style="">
<tr>
<td colspan="2" style="text-align:center; font-size:14px; font-weight:600; line-height:20px;"> {{item.item_name }} </td>
</tr>
<tr>
<td colspan="2" style="text-align:center; font-size:14px; font-weight:600; line-height:20px;">{{ item.batch_number }} - {{ item.part_number }}</td>
</tr>
<tr>
<td colspan="2" style="text-align:center; font-size:13px; font-weight:600; line-height:18px;">{{ item.common_name }}</td>
</tr>
<tr>
<td rowspan="3">
<span style="font-size:12px;">Season of Interest </span>: <span style="font-size:12px;">{{item.season_support|default:' -'}}</span><br />
<span style="font-size:12px;">Flower Colour </span>: <span style="font-size:12px;">{{ item.flower_colour|default:' -' }}</span><br />
</td>
<td style="height:40px;">
<span style="font-size:12px; font-style:italic;">A: {{ item.due_date }}</span><br />
<span style="font-size:12px; font-style:italic;">R: {{ item.ready_date }}</span>
</td>
</tr>
</table>
</td>
<td style="width:4px;"> </td>
</tr>
</table>
</div>
</div>
</div>
{% endif %}
{% endfor %}
</div>
<!--Main Label-->
</body>
</html>
it looks like
in this purchase order(image) for samsung note 3 qty is 2 and ear capsule is 3 so for samsung note 3 it should print 2 times and for ear capsule it should print 3 times (so total number of labels in pdf should be 5 ) but currently how it is priniting is for samsung note 3 one label and for ear capsule it is one label
currently showing pdf
see for each item only one label is printing but now i need based on quantity of each item it should print those many times

