django - Calculated value (aggregation) displays in technical format -
after calculating field in model want display field in template
model:
def _get_total(self): inventory.models import inventory purchase.models import poproduct sales.models import soproduct # "returns total" return inventory.objects.filter(warehouse_bin__material_uom__uom__material=self.id ).aggregate(sum('quantity')) #- soproduct.objects.filter(product__material=self.id).aggregate(sum('quantity')) #poproduct.objects.filter(product__material=self.id).aggregate(sum('quantity')) total = property(_get_total)
template:
<div> <b>total on hand:</b> {{ data.material.total }}</div>
however template displayed value in format instead of plain numeric value
total on hand: {'quantity__sum': decimal('97.00000')}
i trying add parameter , output_field = models.decimalfield() sum function getting error not understand
'decimalfield' object has no attribute 'resolve_expression
'
you returning result set method dict, try returning decimal value:
quantity = inventory.objects.filter(warehouse_bin__material_uom__uom__material=self.id ).aggregate(sum('quantity')) return quantity['quantity__sum']
Comments
Post a Comment