如何制作和提交多个Django表单?

时间:2014-11-16 02:12:34

标签: django multiple-forms

我有两个型号,我想在一个页面中附加多个“Detalle compra”,并将它们全部发送出去。我在管理员中看到了这种行为,但我想这样做。

class Compra(models.Model):
     provedor = models.ForeignKey(Provedor)
     fecha = models.DateTimeField(auto_now_add=True)

class DetalleCompra(models.Model):

    compra = models.ForeignKey(Compra)
    producto = models.ForeignKey(Producto)
    precio_compra = models.DecimalField(max_digits=11, decimal_places=2)
    cantidad = models.DecimalField(max_digits=15,decimal_places=4)

1 个答案:

答案 0 :(得分:1)

我会看看Django formsets。这正是你所寻找的行为我相信。

https://docs.djangoproject.com/en/dev/topics/forms/formsets/