我已将这些模型的形式(通过ModelForm)放在同一页面上,但类似的字段名称对我来说有些问题:
class Transfer(models.Model):
ServiceProvider=models.ForeignKey(ServiceProvider)
Vehicle=models.ForeignKey(Vehicle)
From=models.ForeignKey(Location,related_name='FromLocation')
To=models.ForeignKey(Location,related_name='ToLocation')
PriceUnit=models.ForeignKey(PriceUnit)
Class=models.ForeignKey(Class)
Price=models.CharField(max_length=12)
Date=models.CharField(max_length=16)
class Visit(models.Model):
Location=models.ForeignKey(Location)
FromDate=models.CharField(max_length=16)
ToDate=models.CharField(max_length=16)
class Accommodate(models.Model):
Location=models.ForeignKey(Location)
PriceUnit=models.ForeignKey(PriceUnit)
FromDate=models.CharField(max_length=16)
ToDate=models.CharField(max_length=16)
Price=models.CharField(max_length=12)
我用Google搜索并发现了formset,我该如何解决这个问题?
答案 0 :(得分:2)
您可以传递表格prefix,例如
transfer = TransferForm(prefix="transfer")
visit = VisitForm(prefix="visit")
accommodate = AccommodateForm(prefix="accommodate")