I have the following code:
forms.py:
MAX_DETALLES = 5
Detalle_VentaFormSet = inlineformset_factory(
Venta,
Detalle_Venta,
fields=('cantidad','producto'),
#SI AGREGO EN FIELDS SUBTOTAL, NO ME DEJA MOSTRAR EL FORM DIRECTAMENTE
#readonly_fields = ('subtotal',),
can_delete= True,
extra= MAX_DETALLES
)
class VentaForm(ModelForm):
class Meta:
model = Venta
fields=('cliente', 'fecha','descripcion', 'descuento', 'total')
#inlines = (Detalle_VentaForm,)
#exclude=('',)
Models.py:
# Venta es subclase de Operacion
class Venta(Operacion):
cliente = models.ForeignKey(Cliente, verbose_name= _("cliente"))
class Meta:
verbose_name = _('Venta')
#ordering = ["monto"]
def __unicode__(self):
return unicode(self.fecha)
class Detalle_Venta(models.Model):
venta = models.ForeignKey(Venta)
cantidad = models.IntegerField(default= 1)
producto = models.ForeignKey(Producto)
def _get_subtotal(self):
return self.cantidad*self.producto.precio
subtotal = property(_get_subtotal)
def _get_total(self):
venta.total = venta.total+self.subtotal
return venta.total
venta.total = property(_get_total)
class Meta:
verbose_name = _('Detalle')
#ordering = ["monto"]
def __unicode__(self):
return unicode(self.producto)
It does not show the subtotal, it does not let me add it to the fields of the inline form How to make a total sum?