From 3ab5bf6826dbb99f69a9b9f04c3924308f0a1726 Mon Sep 17 00:00:00 2001 From: Commander1024 Date: Sun, 2 Aug 2020 23:22:47 +0200 Subject: [PATCH] Added signup formcheck signup. --- lostplaces/lostplaces_app/forms.py | 11 +++++++++++ 1 file changed, 11 insertions(+) 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