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