django app同时创建auth.user和app user,并将auth.user_id存储在app.user中
我有一个应用程序,可以通过 auth.user 和应用程序将用户添加到系统中。保存时我想创建用户,然后获取 auth.user.id 并将其添加到 team_user.id 中。
我一直在尝试下面的代码但一无所获。关于我做错了什么有什么建议吗?请指教。
if request.method == 'POST':
form = SimpleRegForm(request.POST)
if form.is_valid():
#form.save()
username = form.cleaned_data['username']
email = form.cleaned_data['email']
password = form.cleaned_data['password1']
user = User.objects.create_user(username, email, password)
new_teammember = form.save(commit=False)
new_teammember.team_user = request.user # I know this is not right.
new_teammember.save()
I have an app that adds a user to the system via auth.user and the app. On save I want to create the user and then get the auth.user.id and add that to a team_user.id.
I've been trying the code below and getting no where. Any suggestions as to what I'm doing wrong? Please advise.
if request.method == 'POST':
form = SimpleRegForm(request.POST)
if form.is_valid():
#form.save()
username = form.cleaned_data['username']
email = form.cleaned_data['email']
password = form.cleaned_data['password1']
user = User.objects.create_user(username, email, password)
new_teammember = form.save(commit=False)
new_teammember.team_user = request.user # I know this is not right.
new_teammember.save()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是 request.user - 这只是用户。
The issue is the request.user - It's just user.