是否有一种直接的方法可以访问 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
我需要获取的是“供应商”发布变量,它不在此表单的已清理数据中,因为供应商字段是父表单的一部分。我能看到抓住它的唯一方法是访问 request.POST 但在那里没有多大成功。
谢谢