Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
清理表单后有什么方法可以更改表单元素?
有些表单逻辑会受到其他字段的影响。ChoiceField在某些情况下,如果表单无效,我想在 clean 函数运行后向 a 添加一个附加选项。有没有办法做到这一点?
ChoiceField
提交无效表单的用户应该获得额外的选项奖励吗?对我来说没有意义......但是是的,您始终可以更改表单字段中可用的选项:
def clean(self): self.fields['some_choice_field'].choices = [[1,'one'],[2, 'two'],[None, 'I refuse to answer']]