def clean_code(self):
    found = False
    promo_code = self.cleaned_data['code']
    if (PromoCode.objects.all().count() == 0):
        raise forms.ValidationError("Sorry, that code isn't valid.")
    codes = PromoCode.objects.all()
    for promotional_code in codes:
        if (promotional_code.code == promo_code):
            if promotional_code.redeemed:
                raise forms.ValidationError('Sorry, promo code already used.')
            elif (promotional_code.user != self.user):
                raise forms.ValidationError("Sorry, that's not your code!")
            else:
                found = True
                break
    if (not found):
        raise forms.ValidationError('Sorry, that code is not valid.')
    return promo_code
def clean_code(self):
    found = False
    promo_code = self.cleaned_data['code']
    if (PromoCode.objects.all().count() == 0):
        raise forms.ValidationError("Sorry, that code isn't valid.")
    codes = PromoCode.objects.all()
    for promotional_code in codes:
        if (promotional_code.code == promo_code):
            if promotional_code.redeemed:
                raise forms.ValidationError('Sorry, promo code already used.')
            elif (promotional_code.user != self.user):
                raise forms.ValidationError("Sorry, that's not your code!")
            else:
                found = True
                break
    if (not found):
        raise forms.ValidationError('Sorry, that code is not valid.')
    return promo_code