Django 内联表单集自定义验证
好的。我可能只是忽略了一些愚蠢的事情。但我在 django 中的内联表单上遇到了问题。我有这样的:
class BaseModelAFormset(forms.models.BaseInlineFormSet):
def clean(self):
for form in self.forms:
print 'I am getting here'
ModelAFormset = inlineformset_factory(ModelB,ModelA, extra=1, formset=BaseModelAFormset)
我的模型实际上并没有命名为 ModelA 和 ModelB。我就是这样做的。
不管怎样,我在一页上有这个表单集,里面有 2 个表单,加上第三个空白表单。 (因此,三个表单中的两个填写了对象。
我点击“保存”,我希望看到两个 “我正在到达这里”
语句,但我只看到一个。
最后,我我正在进行计数检查以进行验证,但是如果从未检查过第二个表单,那么我的计数检查不会有太大作用,所以 print 语句是实现此目的的中间步骤。
Okay. I am probably just overlooking something silly. But I am having an issue with an inline form in django. I have this:
class BaseModelAFormset(forms.models.BaseInlineFormSet):
def clean(self):
for form in self.forms:
print 'I am getting here'
ModelAFormset = inlineformset_factory(ModelB,ModelA, extra=1, formset=BaseModelAFormset)
My models are not really named ModelA and ModelB. I did that as an example.
Anyway, I have this formset on a page and have 2 forms in it plus a third blank one. (So two of the three forms are filled in with objects.
I hit save and I'd expect to see two "I am getting here"
statements, but I only see one.
In the end, I am doing a count check for validation, but if the second form is never checked, my count check won't do much good. So the print statement is an intermediate step towards that. Anyone have any idea why this isn't looping right?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论