django - 我在模型表单集中收到重复/空表单?

标签 django

我正在使用模型表单集用数据库中的数据填充我的 for 。该代码工作正常,但它总是给我一个额外的空表单。

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,})

最佳答案

这是由 extra 参数驱动的。这是the documentation

The number of empty forms that is displayed is controlled by the extra parameter. By default, formset_factory() defines one extra form; the following example will display two blank forms:

EventsFormSet = modelformset_factory(Events, extra=0)

关于django - 我在模型表单集中收到重复/空表单?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17323606/

相关文章:

django - 从 Django/DRF 代码生成 API 蓝图文档

django - 如何在 Google Cloud Platform 上进行 Django 迁移?

python - 用户存在但无法使用 simpleJWT 和 Django Admin 进行身份验证

python - 如何更新模型但在 Django 中返回未修改的模型?

python - Python 中的类似对象的网站设计

jquery - 将其他数据获取到 django 表单下拉选择中

python - Django的manage.py同步数据库错误

python - 如何在django中循环访问用户对象

django - 重写 Django inlineformset_factory has_changed() 以始终返回 True

python - 类型错误 : string indices must be integers, 为什么?