内联Formset不显示数据

时间:2013-05-24 13:01:06

标签: django django-forms formset

我在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中的数据根本没有显示出来。有什么理由吗?

0 个答案:

没有答案