Инструменты для форм Django переключение форм
Я хотел бы сделать условное условие, если is_doctor проверен else. Итак, в настоящее время он отображает форму, если форма проверена, теперь я хотел бы добавить другую форму, если она не проверена, как я могу попытаться сделать это?
urls.py
from django.urls import path
from pages.views import index, ContactWizard, show_message_form_condition
from pages.forms import PickUserType, SignUpForm
contact_forms = [PickUserType, SignUpForm]
urlpatterns = [
path('', index, name='home'),
path('signup/', ContactWizard.as_view(contact_forms,
condition_dict={'1': show_message_form_condition}
),name='signup'),
]
forms.py
from django import forms
from pages.models import Profile
from django.contrib.auth.forms import UserCreationForm
from datetime import date, timedelta
class PickUserType(forms.Form):
is_doctor = forms.BooleanField(required=False)
# verified = FileSystemStorage(location=os.path.join(settings.MEDIA_ROOT, 'doctor'))
# from django.core.files.storage import FileSystemStorage
class SignUpForm(UserCreationForm):
first_name = forms.CharField(max_length=30, required=False, help_text='Optional.')
last_name = forms.CharField(max_length=30, required=False, help_text='Optional.')
email = forms.EmailField(max_length=254, help_text='Required. Inform a valid email address.')
class Meta:
model = Profile
fields = ('username', 'first_name', 'last_name', 'email', 'password1', 'password2', )
views.py
from django.shortcuts import redirect, render
from .forms import SignUpForm, UserProfileForm
from django.contrib.auth import login, authenticate
from formtools.wizard.views import SessionWizardView
def show_message_form_condition(wizard):
# try to get the cleaned data of step 1
cleaned_data = wizard.get_cleaned_data_for_step('0') or {}
# check if the field isDoctor was checked.
return cleaned_data.get('is_doctor', True)
class ContactWizard(SessionWizardView):
def done(self, form_list,form_dict, **kwargs):
print(form_list)
print(form_dict)
print(kwargs)
return redirect('home')