2009-06-05 42 views
3

是否有一種直接的方式來訪問POST變量以完成admin表單字段的clean方法中的一些自定義驗證查找?在表單clean()方法中抓取POST變量

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,但沒有太多成功。

感謝信

回答

7

POST數據包含在self.data