【发布时间】:2018-03-20 09:53:39
【问题描述】:
我在 django redux 注册表单中添加了两个复选框。现在,我可以检查这两个选项,但我希望用户一次选择任何一个。如何做到这一点? 下面是我的代码
models.py
from django.db import models
from django.contrib.auth.models import User
# Create your models here.
class UserSelection(models.Model):
employer = models.BooleanField()
candidate = models.BooleanField()
user = models.OneToOneField(User)
forms.py
from django import forms
from registration.forms import RegistrationFormUniqueEmail
class MyRegForm(RegistrationFormUniqueEmail):
employer = forms.BooleanField()
candidate = forms.BooleanField()
regbackend.py
from registration.backends.default.views import RegistrationView
from .forms import MyRegForm
from .models import UserSelection
class MyRegistrationView(RegistrationView):
form_class = MyRegForm
def register(self, form_class):
new_user = super(MyRegistrationView, self).register(form_class)
p = form_class.cleaned_data['employer']
q = form_class.cleaned_data['candidate']
new_profile = UserSelection.objects.create(user=new_user, employer=p, candidate=q)
new_profile.save()
return new_user
【问题讨论】:
标签: python django django-registration