Skip to content

Instantly share code, notes, and snippets.

@Alir3z4
Created May 7, 2011 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Alir3z4/960517 to your computer and use it in GitHub Desktop.
Save Alir3z4/960517 to your computer and use it in GitHub Desktop.
forms.py
def clean(self):
from decimal import Decimal
cleaned_data = self.cleaned_data
price_mode = cleaned_data.get('price_mode')
price = cleaned_data.get('price')
if price_mode == u'0':
if price:
return self.cleaned_data['price']
return self.cleaned_data['price_mode']
else:
self._errors['price'] = self.error_class([_("Enter valid price!")])
elif price_mode != u'0' and price:
if price_mode == u'1':
self._errors['price'] = self.error_class([_("You select `Free` mode, leave `Price` input empty!")])
elif price_mode == u'2':
self._errors['price'] = self.error_class([_("You select `Please Contact` mode, leave `Price` input empty!")])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment