我的 views.py 文件中有以下代码:
template=get_template('base_settings_trip.html')
setting_data = TransimTripSettings.objects.all()
ttable_data = TransimTripTable.objects.filter(trip_settings=setting_data[0])
SettingFormSet = modelformset_factory(TransimTripSettings, form=TripSettingForm, extra=0)
TtableFormSet = inlineformset_factory(TransimTripSettings, TransimTripTable, form=TripTableForm, extra=4)
setting_form = SettingFormSet(queryset=TransimTripSettings.objects.filter(pid=setting_data[0].pid), prefix="setting")
ttable_form = TtableFormSet(queryset=ttable_data, prefix="ttable")
variables = Context({
"trip_setting_form": setting_form,
"trip_table_form": ttable_form,
})
output = template.render(variables)
return HttpResponse(output)
相关models.py文件:
class TransimTripSettings(models.Model):
pid = models.AutoField(primary_key=True)
trip_purpose_code = models.IntegerField()
travel_mode_code = models.IntegerField()
vehicle_type = models.IntegerField()
average_travel_speed = models.IntegerField()
time_control_point = models.CharField(max_length=15)
class Meta:
db_table = 'transim_trip_settings'
class TransimTripTime(models.Model):
pid = models.AutoField(primary_key=True)
trip_settigns = models.ForeignKey(TransimTripSettings)
start = models.DecimalField(max_digits=4, decimal_places=2)
end = models.DecimalField(max_digits=4, decimal_places=2)
share = models.DecimalField(max_digits=6, decimal_places=4)
class Meta:
db_table = 'transim_trip_time'
SettingFormSet 中的数据正在显示,但 TtableFormSet 中的数据根本没有显示。有什么原因吗?