class Badge(Model):
# ....
class Meta:
unique_together = ('identifier', 'restaurant')
我不明白为什么行为不同。我希望在这两种情况下都显示表单错误。
我刚刚意识到为了验证工作,所有字段都需要在基于类的视图中指定,即使这些字段不应由用户填写。
class BadgesUpdateView(UpdateView):
model = Badge
# restaurant field must be included for validation even if the user does NOT fill it.
fields = ('identifier', 'is_active', 'owner', 'restaurant')
def get_form(self, form_class=None):
form = super().get_form(form_class)
form.fields['restaurant'].widget = forms.HiddenInput()
return form
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)