diff --git a/lostplaces/lostplaces_app/forms.py b/lostplaces/lostplaces_app/forms.py index 6c78036..5e79612 100644 --- a/lostplaces/lostplaces_app/forms.py +++ b/lostplaces/lostplaces_app/forms.py @@ -11,6 +11,18 @@ class ExplorerCreationForm(UserCreationForm): class Meta: model = Explorer 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: diff --git a/lostplaces/lostplaces_app/views.py b/lostplaces/lostplaces_app/views.py index b32dfc1..b2d5924 100644 --- a/lostplaces/lostplaces_app/views.py +++ b/lostplaces/lostplaces_app/views.py @@ -2,7 +2,6 @@ # -*- coding: utf-8 -*- ''' Django views. ''' - from django.shortcuts import render, redirect, get_object_or_404 from django.urls import reverse_lazy from django.views.generic.edit import CreateView