0
我一直試圖在django中使用擴展用戶模型創建自定義註冊表單。我一直在嘗試添加的自定義字段之一是隻能是「員工」或「管理員」的用戶類型。無法在自定義的usercreateform上添加選擇表單域
我signUpForm類看起來像這樣
from .models import EMPLOYEE_TYPE_CHOICES
class SignUpForm(UserCreationForm):
usertype = forms.CharField(
max_length=10,
choices=EMPLOYEE_TYPE_CHOICES,
)
userID = forms.CharField(label="User ID")
class Meta:
model = User
fields = ('username', 'first_name', 'last_name', 'email', 'password1', 'password2', 'userID', 'usertype')
EMPLOYEE_TYPE_CHOICES來自我的models.py它看起來像這樣
EMPLOYEE_TYPE_CHOICES = (
('admin', 'Admin'),
('employee', 'Employee'),
)
class Profile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
ADMIN = 'Admin'
EMPLOYEE = 'Employee'
EMPLOYEE_TYPE_CHOICES = (
(ADMIN, 'Admin'),
(EMPLOYEE, 'Employee'),
)
usertype = models.CharField(
max_length=10,
choices=EMPLOYEE_TYPE_CHOICES,
)
userID = models.CharField(
max_length=10,
)
當運行服務器,我收到錯誤 類型錯誤:初始化 ()得到了一個意想不到的關鍵字參數'選項'
是否有不同的方法用於將選項添加到我的表單字段?