Hi, I want to get the Volume subtotal of my "Contracts" field grouped in my 
template.

I manage to display the total but not the subtotal.


*models.py*
class TransColisCgDlaDet(models.Model):

id_trans_colis = models.AutoField(primary_key=True)
essence = models.CharField(max_length=15, blank=True, null=True, 
verbose_name='Essence')
num_colis = models.CharField(max_length=15, blank=True, null=True, 
verbose_name='Numéro de Colis')
cubage = models.DecimalField(max_digits=6, decimal_places=3, blank=True, 
null=True, verbose_name='Cubage')
num_contrat = models.CharField(max_length=15, blank=False, null=True, 
verbose_name='Numéro de Contrat')

class Meta:
managed = True
db_table = 'TransColisCgDlaDet'
verbose_name = 'Transport de Colis Détaillé '
verbose_name_plural = 'Transports de Colis Détaillés'
ordering = ['num_colis']

def __str__(self):
return str(self.num_colis) 

*views.py*
class TransportDetListView(LoginRequiredMixin,ListView):
login_url = 'admin:login'
model = TransColisCgDlaDet
template_name = "transports/trans_detail.html"
paginate_by = 15

def get_queryset(self):
queryset =  
TransColisCgDlaDet.objects.filter(code_trans__contains=self.kwargs['code_trans']).order_by('num_contrat','essence','
 'num_colis')
lstcolis = queryset.values(
'num_contrat'
).annotate(volcolis=Sum('cubage')).annotate(nb_elts=Sum('nbre_elts'))

return lstcolis

I would the subtotal for the contrats y the template:

Contrat: 2475
-----------------------------------------------------
*Essence  /  Num Colis  /  Cubage*
SIPO  /  22  /  2,378
SIPO  /  23  /  1.251
------------------------------------------------------
Subtotal : 3,629

Contrat: 2500
----------------------------------------------------
*Essence  /  Num Colis  /  Cubage*
SAPELLI  /  572  /  3.001
SAPELLI  /  573  /  1.501
------------------------------------------------------
Subtotal : 4.502

TOTAL:  8.131


Any ideas for how manage this?

Thanks


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/9da7cce8-8512-497c-897c-4c35eb53102en%40googlegroups.com.

Reply via email to