Totals\Subtotals in Django

I'm new to django and I have a problem to get right report layout. I have a model Contract and I have certain problems getting following report layout:

Bussines unit: x
    contractnox  client1  net_price vat price
    contractnoy  client2  net_price vat price
    Bussines unit x subtotals: net_price, vat, price
Bussines unit: y
    you get the point

Totals in the end.

My Contract model is like this:

class Contract(models.Model):
    contract_no = models.IntegerField(verbose_name='Number:')
    client= models.CharField( max_length=50, verbose_name='Client:')
    address = models.CharField( max_length=50, verbose_name='Address:')
    date = models.DateField(, verbose_name='Contract date:')
    price = models.FloatField(max_length=10,default=10.00, verbose_name='Price:')
    vat = models.FloatField(max_length=10,default=0.00, verbose_name='VAT:')
    net_price = models.FloatField(max_length=10,default=0.00, verbose_name='Net price:')
    canceled = models.BooleanField(default=False, verbose_name='Canceled:')
    business_unit=models.ForeignKey('BussinesUnit', on_delete=models.CASCADE, verbose_name='Bussines unit')

I have tried this in view:

b_units= BussinesUnit.objects.all()
contract= Contract.objects.filter(canceled=False)
for unit in b_units:
    data[unit] = contract.filter(,\

    context = {
            'bussines_units': data

In report I did this:

    {% for data, data_items in bussines_units.items %}
     {{ data }}
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
                <td class='detailsCenter' style="width: 5.5%">Contract</td>
                <td class='detailsCenter' style="width: 33%">Client</td>
                <td class='detailsCenter'style="width: 28.5">Adress</td>
                <td class='detailsRight'style="width: 11%">Net price</td>
                <td class='detailsRight' style="width: 11%">VAT</td>
                <td class='detailsRight' style="width: 11%">Price</td>


            {% for data in data_items%}
                {% for x in data%}
                        <td class='detailsCenter' style="width: 5.5%">{{x.contract_no}}</td>
                        <td class='details' style="width: 33%">{{x.client}}</td>
                        <td class='detailsCenter'style="width: 28.5%">{{x.adress}}</td>
                        <td class='detailsRight'style="width: 11%">{{x.net_price}}</td>
                        <td class='detailsRight'style="width: 11%">{{x.vat}}</td>
                        <td class='detailsRight'style="width: 11%">{{x.price}}</td>   

                        <td class='detailsCenter' style="width: 5.5%"></th>
                        <td class='details' style="width: 33%">Subtotal</th>
                        <td class='detailsCenter'style="width: 28.5%">{{data.items_sub}}</td>
                        <td class='detailsRight'style="width: 11%">{{data.net_price_sub}}</td>
                        <td class='detailsRight'style="width: 11%">{{data.vat_sub}}</td>
                        <td class='detailsRight'style="width: 11%">{{data.price_sub}}</td>

            {% endfor %}
    {% endfor %}

I get required results, but subtotals seem to be placed in multiple rows and I want them placed in single row, so any assistance on this regard would be great. Attached is the screenshot of scattered items.

enter image description here

I'm using xhtml2pdf to get pdf reports, if that is of any use for this problem.

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum