从内联表单clean()访问父表单的cleaned_data [英] access parent form's cleaned_data from inline form clean()

查看:64
本文介绍了从内联表单clean()访问父表单的cleaned_data的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个内联表单的主表单。可以从内联窗体的clean函数访问主窗体的cleaned_data吗?



这就是我要问的原因。



主窗体具有一个字段,用于定义物业是出售还是租赁。然后,内联表单显示销售价格字段或租赁金额和押金字段。我正在尝试验证是否要出售该物业,那么租赁和存款字段应该为空。



我可以在前端界面的视图中执行此操作,

解决方案

否,这些形式是分开的,但是对于前端和管理员而言,都可以在form.py中完成吗?对象并且彼此完全不知道。但是您要为所有表单提供相同的 data ,因此您应该能够检查 self.data 中的字段。 / p>

I have a main form that has an inline-form. Is it possible to access the main form's cleaned_data from the inline-form's clean function?

Here is why I am asking.

The main form has a field to define if a property is for-sale or to lease. The inline form then displays either a sale price field or fields for the lease amount and deposit. I am trying to validate that if the property is for sale, then the lease and deposit fields should be empty.

I can do this in a view for the frontend interface, but is it possible to be done in forms.py for both the frontend and the admin?

解决方案

No, these forms are separate objects and are completely unaware of each other. But you are providing same data to all forms, so you should be able to check fields from self.data.

这篇关于从内联表单clean()访问父表单的cleaned_data的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆