기본 django 사용자 (django 1.6 사용)를 확장하기 위해 프로파일 모델을 만들었습니다 그러나 프로파일 모델을 올바르게 저장할 수 없습니다.OneToOne 필드로 모델 저장
여기 내 모델 :
from django.contrib.auth.models import User
class Profile(models.Model):
user = models.OneToOneField(User)
mobilephone = models.CharField(max_length=20, blank=True)
여기에 WDSL 파일에서 personrecords을 업데이트 내 셀러리-작업은 다음과 같습니다
@task()
def update_local(user_id):
url = 'http://webservice.domain.com/webservice/Person.cfc?wsdl'
try:
#Make SUDS.Client from WSDL url
client = Client(url)
except socket.error, exc:
raise update_local.retry(exc=exc)
except BadStatusLine, exc:
raise update_local.retry(exc=exc)
#Make dict with parameters for WSDL query
d = dict(CustomerId='xxx', Password='xxx', PersonId=user_id)
try:
#Get result from WSDL query
result = client.service.GetPerson(**d)
except (socket.error, WebFault), exc:
raise update_local.retry(exc=exc)
except BadStatusLine, exc:
raise update_local.retry(exc=exc)
#Soup the result
soup = BeautifulSoup(result)
#Firstname
first_name = soup.personrecord.firstname.string
#Lastname
last_name = soup.personrecord.lastname.string
#Email
email = soup.personrecord.email.string
#Mobilephone
mobilephone = soup.personrecord.mobilephone.string
#Get the user
django_user = User.objects.get(username__exact=user_id)
#Update info to fields
if first_name:
django_user.first_name = first_name.encode("UTF-8")
if last_name:
django_user.last_name = last_name.encode("UTF-8")
if email:
django_user.email = email
django_user.save()
#Get the profile
profile_user = Profile.objects.get_or_create(user=django_user)
if mobilephone:
profile_user.mobilephone = mobilephone
profile_user.save()
django_user.save()
가 잘 작동하지만, profile_user.save()
가 작동하지 않습니다. 임 :이 오류가 발생했습니다. AttributeError: 'tuple' object has no attribute 'mobilephone'
누구든지 무엇이 잘못 되었습니까?
좋아요! 내 질문에 max_length를 잊어 버렸지만 내 코드에는 없습니다. –
나는 몰랐다. 그러나이 매개 변수없이 django 서버를 실행할 수 없기 때문에 이상하게 보였다 (모델 유효성 검사는 실패 할 것이다) – dydek