我需要在ModelForm中为具有多个额外字段的manytomanyfield字段创建一个字段。你能帮助我吗? 例如,我有一个配方模型,其中包含一个与Malting相关的ManyToManyField:
models.py
class Recipe(models.Model):
name = models.CharField(max_length=50)
observaciones = models.CharField(max_length=200)
litros_finales = models.IntegerField()
lavado = models.IntegerField()
rendimiento = models.FloatField(null=False)
equipment = models.ForeignKey(Equipment, null=True,blank=True,on_delete=models.CASCADE)
malts = models.ManyToManyField(Malt, through='Malting')
style = models.ForeignKey(Style, null=True,blank=True,on_delete=models.CASCADE)
class Malting(models.Model):
malt = models.ForeignKey(Malt,on_delete=models.CASCADE)
recipe = models.ForeignKey(Recipe,on_delete=models.CASCADE)
tiempo = models.TimeField()
cantidad = models.FloatField(null=False)
我需要创建一个表格,使我可以将Recipe和Malteado与该字段的额外数量和时间相关联。
谢谢! 卢西亚诺。