Is there a straightforward way to access a POST variable to complete some custom validation lookups in a admin form field's clean method?
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
What I need to grab is the 'supplier' post variable which is not in this form's cleaned data because the supplier field is part of the parent form. Only way I can see of grabbing it is accessing request.POST but not having much success there.
Thank-you
The POST data is contained in self.data
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With