我正在尝试使用 django-rest-auth 将数据从我的 angularJS 应用程序传递到 django。
在我的控制台中,我可以看到数据正确到达(尤其是“性别”和“yob”)。
但是,似乎在调用“cleaned_data”之后 - 数据并没有最终出现在我的 django 用户模型中
注意-我设置了两个用户模型(一个是股票 django 用户表,另一个是我在 models.py 中创建的用户表)
from allauth.account.adapter import DefaultAccountAdapter # refer to allauth.account.adapter
from stashd.models import User, AccountProfile
import datetime, json
class MyAccountAdapter(DefaultAccountAdapter):
def save_user(self, request, user, form, commit=True):
system_account = super(StashdAccountAdapter, self).save_user(request, user, form, commit)
print form
## Print form shows all the data, but the cleaned_data get's rid of it
data = form.cleaned_data
first_name = data.get('first_name')
username = data.get('username')
last_name = data.get('last_name')
email = data.get('email')
# gender = data.get('gender')
# yob = data.get('yob')
# dob = datetime.date(int(yob), 1, 1)
info = {}
# for k, v in [('first', username), ('first', first_name), ('last', last_name), ('email', email)]:
# if v:
# info[k] = v
for k, v in [('email', email)]: #,('dob',dob),('gender',gender)
if v:
info[k] = v
user = User(**info)
user.save()
AccountProfile(user=user, account=system_account).save()
return system_account