我想在管理员更改表格中强制执行整个内联表单集.因此,在我目前的情况下,当我点击发票表单上的保存时(在管理员中),内联订单表格为空白.我想阻止人们创建没有订单关联的发票.
有人知道一个简单的方法吗?
required=True
模型字段上的正常验证如()似乎在此实例中不起作用.
是否有一种简单的方法来访问POST变量以在管理表单字段的clean方法中完成一些自定义验证查找?
def clean_order_price(self):
if not self.cleaned_data['order_price']:
try:
existing_price = ProductCostPrice.objects.get(supplier=supplier, product_id=self.cleaned_data['product'], is_latest=True)
except ProductCostPrice.DoesNotExist:
existing_price = None
if not existing_price:
raise forms.ValidationError('No match found, please enter new price')
else:
return existing_price.cost_price_gross
else:
return self.cleaned_data
Run Code Online (Sandbox Code Playgroud)
我需要抓住的是"供应商"邮政变量,它不在此表单的清理数据中,因为供应商字段是父表单的一部分.我能看到抓住它的唯一方法是访问request.POST但在那里没有取得多大成功.
谢谢