CreateWithInlinesView 表单验证
CreateWithInlinesView validation in form
有人知道如何在使用 Django Extra Views 中的 CreateWithInlinesView
时验证表单吗?
令人惊讶的是 def clean(self)
和 def clean_name_of_the_field
方法在那里不起作用。我已经在基于函数的视图上检查过它,因此它们在 CreateWithInlinesView
中确实不起作用。我仍然可以在模型中使用验证器和 def clean()
,但我更愿意在表单中使用...
如果您在 CreateWithInlinesView
验证方面有任何经验 - 请告诉我。
谢谢!
我知道这已经晚了,但我也遇到了同样的问题。我刚刚添加了一些内容来帮助理解。这可以在视图中完成。
我找到了解决方案
class ModelCreate(CreateWithInlinesView):
model = models.Model
inlines = [ModelInline]
form_class = forms.ModelForm
success_url = reverse_lazy("app:related_name")
def forms_valid(self, form, inlines):
self.object = form.save()
"""Write your extra code in here"""
return HttpResponseRedirect(self.get_success_url())
有人知道如何在使用 Django Extra Views 中的 CreateWithInlinesView
时验证表单吗?
令人惊讶的是 def clean(self)
和 def clean_name_of_the_field
方法在那里不起作用。我已经在基于函数的视图上检查过它,因此它们在 CreateWithInlinesView
中确实不起作用。我仍然可以在模型中使用验证器和 def clean()
,但我更愿意在表单中使用...
如果您在 CreateWithInlinesView
验证方面有任何经验 - 请告诉我。
谢谢!
我知道这已经晚了,但我也遇到了同样的问题。我刚刚添加了一些内容来帮助理解。这可以在视图中完成。
我找到了解决方案
class ModelCreate(CreateWithInlinesView):
model = models.Model
inlines = [ModelInline]
form_class = forms.ModelForm
success_url = reverse_lazy("app:related_name")
def forms_valid(self, form, inlines):
self.object = form.save()
"""Write your extra code in here"""
return HttpResponseRedirect(self.get_success_url())