我创建了一个配置文件模型来扩展默认的 django 用户(使用 django 1.6)但我无法正确保存配置文件模型。
这是我的模型:
from django.contrib.auth.models import User
class Profile(models.Model):
user = models.OneToOneField(User)
mobilephone = models.CharField(max_length=20, blank=True)
这是我的芹菜任务,它从 wdsl 文件更新人员记录:
@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'
有人看到我做错了什么吗?