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
取得する必要があるのは、「supplier」post変数です。これは、supplierフィールドが親フォームの一部であるため、このフォームのクリーンアップされたデータには含まれていません。それをつかむことができる唯一の方法は、request.POSTにアクセスすることですが、そこではあまり成功していません。
ありがとうございました