我想在另一个表格中显示表格。在另一个表格中显示表格
例如,我有这些模型:
class Measure(models.Model):
length = models.ForeignKey(Statistics, related_name='Length', null=True, blank=True)
surface_area = models.ForeignKey(Statistics, related_name='Surface area+', null=True, blank=True)
section_area = models.ForeignKey(Statistics, related_name='Section area+', null=True, blank=True)
volume = models.ForeignKey(Statistics, related_name='Volume', null=True, blank=True)
diameter = models.ForeignKey(Statistics, related_name='Diameter', null=True, blank=True)
class Statistics(models.Model):
total = models.FloatField('Total', null=True, blank=True)
avg = models.FloatField('Average', null=True, blank=True)
min = models.FloatField('Minimum', null=True, blank=True)
max = models.FloatField('Maximum', null=True, blank=True)
standard_deviation = models.FloatField('Standard deviation', null=True, blank=True)
,然后我有这些形式与之前的机型:
class StatisticsForm(forms.ModelForm):
class Meta:
model = Statistics
fields = '__all__'
class MeasureForm(forms.ModelForm):
class Meta:
model = Measure
fields = '__all__'
# Here I have to say that the right form for each field is the StatisticForm
表单中的ForeignKey的呈现为一个组合框包括所有在另一个表中的对象(在我的情况下,统计表),我想用StatsForm的对象替换组合框,所以我可以控制我呈现统计对象的方式
非常感谢。
这不是很清楚你在问什么,但它听起来像你正在寻找[formsets](https://docs.djangoproject.com/en/dev/topics/forms/formsets/) – solarissmoke
The ForeignKey in the窗体呈现为一个组合框包括在另一个表中的所有对象(在我的情况下,统计表),我想用统计窗体的对象替换组合框,所以我可以控制我呈现统计对象的方式 –