django多重嵌套_具有多重继承的Django表单

django多重嵌套

Sometimes you want to validate only parts of a Django form. A use case for this would be a user profile. A user may have an extensive user profile, but sometimes you only want to validate a subset of the form fields, e.g. the city and the phone number, when providing a profile edit form. On another page you might want to offer a username change. If you try to validate one of those forms using POST data for the provided fields only, the validation will fail because there are other mandatory fields. In that case, Python’s support for multiple inheritance may suit you.

有时您只想验证Django表单的一部分。 一个用例是用户个人资料。 用户可能具有广泛的用户个人资料,但有时在提供个人资料编辑表单时,您只想验证表单字段的子集,例如城市和电话号码。 在另一页上,您可能想更改用户名。 如果您尝试仅对提供的​​字段使用POST数据来验证其中一种表格,则验证将失败,因为还有其他必填字段。 在这种情况下,Python对多重继承的支持可能适合您。

多种形式继承 (Multiple form inheritance)

First, define a form for all the form field subsets you might need to validate.

首先,为您可能需要验证的所有表单域子集定义一个表单。

 class class FormAFormA (( forms
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值