Add various details to a sale Django

0

I have 2 apps client and sale where the client has only one client table

class Cliente(models.Model):
    nombre = models.CharField(max_length=100, verbose_name='Nombres')

and sale has 2 tables (Sale and retail detail) and product but that pulls from another table.

class Venta(models.Model):
    cliente = models.ForeignKey(Cliente,on_delete=models.CASCADE,verbose_name='Cliente')
    fecha =  models.DateField()
    detalle = models.CharField(max_length=300, verbose_name='Detalle del pedido')


class DetalleVenta(models.Model):
    producto = models.ForeignKey(Producto,on_delete=models.CASCADE,verbose_name='Producto')
    cantidad = models.IntegerField(verbose_name='Cantidad')
    venta = models.ForeignKey(Venta,on_delete=models.CASCADE, verbose_name='Venta')

The problem I have is how I can add several sales details since they can be 1 or many details that can be generated when making a sale in the same form. Since if I create a form with the 2 models, there is only one detail recorded and with its sale but if they are more details?

    
asked by Pancho Jay 25.01.2018 в 23:49
source

1 answer

1

I think what you need is to use formsets from Django. That way you can, in the same invoice, include several products.

I suggest you take a look at the official Django documentation on this subject: link

It's even a little easier if you decide to use ModelForms and ModelFormsets. In that case you can use Inline Formsets:

link

    
answered by 26.01.2018 / 00:13
source