2013-06-26 17 views
0

我正在使用模型formset來填充數據庫中的數據。代碼工作正常,但它總是給我一個額外的空表單。我在模型formset中獲取重複/空的表單?

EventsFormSet = modelformset_factory(Events) 
formset = EventsFormSet(queryset=Events.objects.filter(date__day=current_day, date__month=current_month, date__year = current_year)) 
return render_to_response(template_name, {"formset": formset,}) 

回答

2

這是由extra參數驅動的。這裏是the documentation

顯示的空白表格的數量由額外的參數控制。默認情況下,formset_factory()定義了一個額外的表單;以下示例將顯示兩個空格:

EventsFormSet = modelformset_factory(Events, extra=0) 
+0

謝謝!我不知道我是如何錯過的。等待接受答案! –