diff --git a/lostplaces/lostplaces_app/forms.py b/lostplaces/lostplaces_app/forms.py index 0d404c6..5e79612 100644 --- a/lostplaces/lostplaces_app/forms.py +++ b/lostplaces/lostplaces_app/forms.py @@ -13,6 +13,17 @@ class ExplorerCreationForm(UserCreationForm): fields = ('username', 'email') voucher = forms.CharField(max_length=10) + def is_valid(self): + super().is_valid() + sumitted_voucher = self.cleaned_data.get('voucher') + try: + fetched_voucher = Voucher.objects.get(code=sumitted_voucher) + except Voucher.DoesNotExist: + return False + + fetched_voucher.delete() + return True + class ExplorerChangeForm(UserChangeForm): class Meta: model = Explorer