简体   繁体   English

Django 将变量从一个步骤附加到另一个步骤

[英]Django Attach variables from one step to another

How would I grab the 2nd form and add it to the first form then selectively not allow that user to login.我将如何获取第二个表单并将其添加到第一个表单然后选择性地不允许该用户登录。 In the Doctorwizard done function.在 Doctorwizard 中完成了 function。

maybe add a variable status?也许添加一个变量状态?

etc.等等

username,password,email,first_name,last_name,verified

views.py视图.py

from django.core.files.storage import FileSystemStorage
import os
from django.conf import settings
class DoctorWizard(SessionWizardView):
    file_storage = FileSystemStorage(location=os.path.join(settings.MEDIA_ROOT, 'doctor'))
    template_name = "registration/signup.html"
    form_list = [SignUpForm,verify]
    
    def done(self, form_list, **kwargs):
        data=process_data(form_list)
        return redirect('home')

forms.py forms.py

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', )

class verify(forms.Form):
    verified = forms.ImageField(required=True)
    class Meta:
        model = Profile
        fields = ('verified',)

models.py模型.py

class Profile(AbstractUser):
    
    bio = models.TextField(max_length=100, blank=True)
    phone_number = PhoneNumberField(max_length=25, region="US")
    birth_date = models.DateField(blank = True, null = True) 
    is_doctor = models.BooleanField(default=False)
    verified = models.ImageField(upload_to='media/doctor')
    date_created = models.DateTimeField(auto_now_add=True)
    avatar = models.ImageField(default='default.png', upload_to='')
def done(self, form_list, **kwargs):
        process_data(form_list)
        userCreate = form_list[0]
        userCreate.save()
        username = userCreate.cleaned_data.get('username')
        raw_password = userCreate.cleaned_data.get('password1')
        user = authenticate(username=username, password=raw_password)
        if user:
            user.verified=form_list[1].cleaned_data.get('verified')
            user.is_doctor=True
            user.is_active=False
            user.save()

Just grab the user and access it's fields.只需抓住用户并访问它的字段。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将一个模板文件中的变量包含到 Django 中的另一个模板中 - Include variables from one template file into another template in Django Django - 将 Session 变量从一个视图传递到另一个视图(“请求”未定义) - Django - Pass Session Variables From One View To Another ('request' is undefined) 如何将变量从一个视图传递到另一个视图并使用 Django 中最后一个视图的 URL 进行渲染? - How do I pass variables from one view to another and render with the last view's URL in Django? Django - 将变量从函数传递到另一个函数 - Django - Passing variables from a function to another 如何将变量从一个视图发送到另一个视图? - How to send variables from one views to another? 我如何将数据(变量)从一个 html 页面传输到另一个页面,这里我使用 html 和 django 框架 - How i transfer data(variables) from one html page to another page, here i am using html & django framework Django从一个查询集中排除另一个查询集 - Django excluding one queryset from another Django 从一个视图重定向到另一个视图 - Django redirecting from one view to another 将上下文从一个Django视图传递到另一个 - Passing Context From One Django View To Another 在Django中将字段从一个实例复制到另一个实例 - Copy fields from one instance to another in Django
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM