プロジェクトの実行中にこのエラーが表示されます
/accounts/EmpReg/の FieldError
キーワード「ユーザー名」をフィールドに解決できません。選択肢は次のとおりです。companytype、contactno、contactperson、id、jobs、user
ビュー.py
class User(models.Model):
username = models.CharField(_('username'), max_length=30, unique=True)
first_name = models.CharField(_('first name'), max_length=30, blank=True)
last_name = models.CharField(_('last name'), max_length=30, blank=True)
email = models.EmailField(_('e-mail address'), blank=True)
password = models.CharField(_('password'), max_length=128)
companyname = models.CharField(_('companyname'), max_length=50)
usertype = models.CharField(_('usertype'), max_length=30)
is_staff = models.BooleanField(_('staff status'), default=False)
is_active = models.BooleanField(_('active'), default=True)
is_superuser = models.BooleanField(_('superuser status'), default=False)
last_login = models.DateTimeField(_('last login'), default=timezone.now)
date_joined = models.DateTimeField(_('date joined'), default=timezone.now)
groups = models.ManyToManyField(Group, verbose_name=_('groups'),blank=True)
user_permissions = models.ManyToManyField(Permission,verbose_name=_('user permissions'), blank=True)
class RegistrationProfile(models.Model):
user = models.ForeignKey(User, unique=True)
activation_key = models.CharField(max_length=40)
key_generated = models.DateTimeField()
objects = RegistrationManager()
フォーム.py
class EmpRegistrationForm(forms.Form):
username = forms.CharField(max_length=30,widget=forms.TextInput)
email = forms.EmailField(widget=forms.TextInput))
password1 = forms.CharField(widget=forms.PasswordInput)
password2 = forms.CharField(widget=forms.PasswordInput)
usertype = forms.CharField(widget=forms.HiddenInput)
companyname = forms.CharField(widget=forms.TextInput)
companytype = forms.ChoiceField(choices=PREFERRED_COMPANYTYPE, widget=forms.RadioSelect())
contactno = forms.CharField(widget=forms.TextInput)
contactperson = forms.CharField(widget=forms.TextInput)
tos = forms.BooleanField()
ビュー.py
def empreg(request):
if request.method == 'POST':
form = EmpRegistrationForm(request.POST)
if form.is_valid():
user = RegistrationProfile.objects.create_inactive_user(user__username=form.cleaned_data['username'],password=form.cleaned_data['password1'],email=form.cleaned_data['email'],)
user.companyname = form.cleaned_data['companyname']
user.usertype = form.cleaned_data['usertype']
user.save()
e=EmployerReg_Form(user=user, companytype=form.cleaned_data['companytype'],contactno=form.cleaned_data['contactno'],contactperson=form.cleaned_data['contactperson'])
e.save()
return HttpResponseRedirect('/accounts/EmpReg_Complete/')
else:
form = EmpRegistrationForm()
return render_to_response('registration/empregform.html', { 'form': form }, context_instance=RequestContext(request))
models.py
class EmployerReg_Form(models.Model):
user = models.ForeignKey(User, unique=True)
companytype = models.CharField(max_length=20)
contactno = models.CharField(max_length=30)
contactperson = models.CharField(max_length=30)
PREFERRED_COMPANYTYPE = (
('Company', 'Company'),
('Consultancy', 'Consultancy'),
)
上記のコードを確認して、私が間違っているところを助けてください