【问题标题】:django inlineformset_factory - how to judge whether a form out of the formset was emptydjango inlineformset_factory - 如何判断formset外的一个form是否为空
【发布时间】:2011-01-04 09:34:33
【问题描述】:

如果表单集中的所有表单都有效,则基于 inlineformset_factory 创建的表单集始终返回 True。当表单集中的表单未填写时,它也返回 True。未填写在这里意味着用户没有插入至少一个值。至少这是我发现的。

有没有办法知道表单集中的表单是空的?例如,下面我不想设置用户消息,即对象已创建,而实际上对象并未创建。

CashExpenditureFormSet = inlineformset_factory(Project, CashExpenditure, form=CashExpenditureForm, can_delete=False, extra=1, max_num=1)

    if request.method == 'POST':
        cash_expenditure_formset = CashExpenditureFormSet(request.POST, request.FILES, instance=project)
        if cash_expenditure_formset.is_valid():
            cash_expenditure_formset.save()
            request.user.message_set.create(message='The Cash Expenditure was added successfully to project: "%s".' % project.__str__())

【问题讨论】:

    标签: django


    【解决方案1】:

    这与我在另一个问题上发布的答案密切相关,我自己处理过这个问题:Inline Form Validation in Django

    【讨论】:

      猜你喜欢
      • 2019-03-20
      • 1970-01-01
      • 2012-03-15
      • 2014-07-18
      • 2013-03-11
      • 1970-01-01
      • 1970-01-01
      • 2019-03-24
      • 1970-01-01
      相关资源
      最近更新 更多