我尝试使用django-rest-auth将数据从angularJS应用传递到django。
在我的控制台中,我可以看到数据正确到达(特别是'性别'以及' yob')。
然而,似乎在" cleaning_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
答案 0 :(得分:0)
您需要在表单上调用form.is_valid()
来填充cleaning_data
答案 1 :(得分:0)