def clean_code(self):
    code = self.cleaned_data['code'].strip().upper()
    if (not code):
        raise forms.ValidationError(_('Please enter a voucher code'))
    try:
        voucher = Voucher.objects.get(code=code)
    except Voucher.DoesNotExist:
        pass
    else:
        if ((not self.voucher) or (voucher.id != self.voucher.id)):
            raise forms.ValidationError((_("The code '%s' is already in use") % code))
    return code
def clean_code(self):
    code = self.cleaned_data['code'].strip().upper()
    if (not code):
        raise forms.ValidationError(_('Please enter a voucher code'))
    try:
        voucher = Voucher.objects.get(code=code)
    except Voucher.DoesNotExist:
        pass
    else:
        if ((not self.voucher) or (voucher.id != self.voucher.id)):
            raise forms.ValidationError((_("The code '%s' is already in use") % code))
    return code