Python 如何使用模型字段在views.py中创建方程(初学者)

Python 如何使用模型字段在views.py中创建方程(初学者),python,django,django-templates,django-views,Python,Django,Django Templates,Django Views,我有一个这样的模型: class Factura(models.Model): nombre_cliente = models.ForeignKey(Cliente) importe_Total= models.FloatField() importe_sin_iva = models.FloatField() def ver_factura(request, id_factura): fact = Factura.objects.get(pk = id_fac

我有一个这样的模型:

class Factura(models.Model):
    nombre_cliente = models.ForeignKey(Cliente)
    importe_Total= models.FloatField()
    importe_sin_iva = models.FloatField()
def ver_factura(request, id_factura):
    fact = Factura.objects.get(pk = id_factura)
    cliente = Cliente.objects.get(factura = fact)
    template = 'verfacturas.html'

    extra_context = dict()
    extra_context['fact'] = fact
    extra_context['cliente'] = cliente

    return render_to_response(template, extra_context)
我有这样的看法:

class Factura(models.Model):
    nombre_cliente = models.ForeignKey(Cliente)
    importe_Total= models.FloatField()
    importe_sin_iva = models.FloatField()
def ver_factura(request, id_factura):
    fact = Factura.objects.get(pk = id_factura)
    cliente = Cliente.objects.get(factura = fact)
    template = 'verfacturas.html'

    extra_context = dict()
    extra_context['fact'] = fact
    extra_context['cliente'] = cliente

    return render_to_response(template, extra_context)
此函数在表格中显示账单的数据(西班牙语的Factura)。好啊我需要的是从数据库中获取值:“importe_sin_iva=models.FloatField()”,并进行乘法:(importe_sin_iva x 0.21)并在模板中显示该结果。之后,我必须得到这个乘法的结果,并将其(+)添加到importe_sinu_iva数据中:“乘法的结果+importe_sinu iva”

问题是,我想在views.py中这样做,所以我不需要定制模板标签来处理这个问题。使用我现在在函数中拥有的代码,我可以访问此账单(Factura)客户端的所有数据

这看起来是一个非常基本的问题,但我非常感谢您的帮助


谢谢

我不知道你们是已经有了总价还是没有增值税的价格。如果我理解,您想通过importe_sinu_iva*1.21计算总成本

extra_context['importe_iva_incluida'] = fact.importe_sin_iva * 1.21
如果您想在模板中显示VAT,只需执行以下操作

extra_context['iva'] = fact.importe_sin_iva * 0.21

是的,我错了。我没有总价。我想通过添加这一行的结果来计算总价:“extra_context['iva']=fact.importe_sinu iva*0.21”和fact.importe_sinu iva。我该怎么做?我是否应该将其保存在变量中,然后进行添加?。谢谢你的帮助。对不起打扰你了。谢谢你的帮助