diff --git a/lostplaces/lostplaces_app/forms.py b/lostplaces/lostplaces_app/forms.py index d545711..0d404c6 100644 --- a/lostplaces/lostplaces_app/forms.py +++ b/lostplaces/lostplaces_app/forms.py @@ -7,15 +7,11 @@ from django import forms from django.contrib.auth.forms import UserCreationForm, UserChangeForm from .models import Explorer, Place, PlaceImage, Voucher -class VoucherVerifyForm(forms.ModelForm): - class Meta: - model = Voucher - fields = ['code'] - class ExplorerCreationForm(UserCreationForm): class Meta: model = Explorer fields = ('username', 'email') + voucher = forms.CharField(max_length=10) class ExplorerChangeForm(UserChangeForm): class Meta: diff --git a/lostplaces/lostplaces_app/urls.py b/lostplaces/lostplaces_app/urls.py index 78af2df..de6fd79 100644 --- a/lostplaces/lostplaces_app/urls.py +++ b/lostplaces/lostplaces_app/urls.py @@ -1,7 +1,6 @@ from django.urls import path from .views import ( hello_world, - VoucherVerifyView, place_detail_view, place_list_view, SignUpView, @@ -11,7 +10,6 @@ from .views import ( urlpatterns = [ path('hello_world/', hello_world), # You know what this is :P - path('voucher/', VoucherVerifyView.as_view(), name='enter_voucher'), path('signup/', SignUpView.as_view(), name='signup'), path('place//', place_detail_view, name='place_detail'), path('place/create/', PlaceCreateView.as_view(), name='place_create'), diff --git a/lostplaces/lostplaces_app/views.py b/lostplaces/lostplaces_app/views.py index 2920e70..a943461 100644 --- a/lostplaces/lostplaces_app/views.py +++ b/lostplaces/lostplaces_app/views.py @@ -2,18 +2,18 @@ # -*- 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, UpdateView from django.views import View from django.http import Http404 -from .forms import ExplorerCreationForm, PlaceForm, PlaceImageCreateForm, VoucherVerifyForm +from .forms import ExplorerCreationForm, PlaceForm, PlaceImageCreateForm from .models import Place, PlaceImage, Voucher # Create your views here. +''' class VoucherVerifyView(View): formclass = VoucherVerifyForm fields = ['code'] @@ -23,12 +23,11 @@ class VoucherVerifyView(View): return render(request, 'voucher-verify.html', {'voucher_form': voucher_form}) def post(self, request, *args, **kwargs): - voucher_form = VoucherVerifyForm(request.POST) - + voucher_form = VoucherVerifyForm(request.POST) + print(voucher_form.values('code')) if voucher_form.is_valid(): # Compare voucher from form with available vouchers in Voucher. for voucher in Voucher.objects.all(): - print(voucher.code) if voucher.code == voucher_form.cleaned_data.get('code'): kwargs_to_pass = { 'voucher_pk': voucher.pk @@ -38,6 +37,7 @@ class VoucherVerifyView(View): return redirect(reverse_lazy('enter_voucher')) else: return redirect(reverse_lazy('enter_voucher')) +''' class SignUpView(CreateView): form_class = ExplorerCreationForm