Note that there are some explanatory texts on larger screens.

plurals
  1. POTransforming data in Django. Want to be able to apply sums to a decimal field
    primarykey
    data
    text
    <p>I have a model like this.</p> <pre><code>#models.py class Payment(models.Model): unit_price = models.DecimalField(max_digits=12, decimal_places=2) discount = models.DecimalField(max_digits=12, decimal_places=2) payment_terms = models.CharField(max_length=80) amount = models.DecimalField(max_digits=12, decimal_places=2) VAT = models.DecimalField(max_digits=4, decimal_places=2) def __unicode__(self): return unicode(self.unit_price) class Invoice(models.Model): client = models.ForeignKey(Client) payment = models.ForeignKey(Payment) date = models.DateField() invoice_no = models.CharField(max_length=16) work_orders = models.ManyToManyField(Work_Order) contract_info = models.ForeignKey(Contract_Info) def __unicode__(self): return self.invoice_no </code></pre> <p>What I want to focus is payment so try forgetting everything else. Here is my views.py.</p> <pre><code>#views.py @login_required def invoice_details(request, id=1): invoices_list = Invoice.objects.filter(pk=id) invoice = get_object_or_404(Invoice, pk=id) client = invoices_list[0].client work_orders = invoices_list[0].work_orders payment = invoices_list[0].payment return render_to_response(('invoice_details.html', locals()), {'work_orders': work_orders,'payment':payment,'client': client, 'invoice': invoice ,'invoices_list': invoices_list}, context_instance=RequestContext(request)) </code></pre> <p>And here is my template.</p> <pre><code>&lt;h1&gt;invoice_details.html&lt;h1&gt; {{ payment.amount }} </code></pre> <p>The template displays the payment amount in a decimal value. What I want to be able to do is some sums with {{payment.amount}}. Suppose if I wanted to multiply whatever the value<br> {{payment.amount}} by let say 2. How would I do this? </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload