내가 얻는 오류는 사용자를 사용자 정의 양식으로 확장하고 "user_id"필드는 "auth_user"테이블에 연결된 "속성"이며 사용하려면 두 테이블이 모두 필요합니다. 내 사용자 정의 양식 속성 및 django 사용자의 모양.
내 models.py
from __future__ import unicode_literals
from django.contrib.auth.models import User
from django.db import models
# Create your models here.
class Profile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
first_name = models.CharField(max_length=100)
last_name = models.CharField(max_length=100)
Matricula = models.CharField(max_length=25)
forms.py
class SignupForm(forms.ModelForm):
class Meta:
model = Profile
fields = ('first_name', 'last_name', 'Matricula')
#Saving user data
def signup(self, request, user):
user.first_name = self.cleaned_data['first_name']
user.last_name = self.cleaned_data['last_name']
user.Matricula = self.cleaned_data['Matricula']
user.save()
##Save profile
profile = Profile()
Profile.user = user
profile.Matricula = self.cleaned_data['Matricula']
profile.save()
나는 시도했다 :
user = models.OneToOneField(User, on_delete=models.CASCADE)
하지만 오류가 발생합니다. 오류
ForeignKey를 사용하거나 OneToOneField를 올바르게 사용할 수 있다고 생각하십니까?
대문자 사용에주의해야합니다. 인스턴스가 아닌 클래스에 사용자 값을 할당했습니다. 그것은해야한다:
profile = Profile()
profile.user = user
또는 더 나은 :
profile = Profile(user=user)
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다