本文整理汇总了Python中accounts.models.UserProfile.create方法的典型用法代码示例。如果您正苦于以下问题:Python UserProfile.create方法的具体用法?Python UserProfile.create怎么用?Python UserProfile.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类accounts.models.UserProfile
的用法示例。
在下文中一共展示了UserProfile.create方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setup
# 需要导入模块: from accounts.models import UserProfile [as 别名]
# 或者: from accounts.models.UserProfile import create [as 别名]
def setup(request):
u = User.objects.create_user(username='jsmith', email='[email protected]', password='password')
u.save()
prof = UserProfile.create(user=u)
color = Color.create(50, 50, 50)
color.save()
prof.color = color
prof.save()
u = User.objects.create_user(username='jsmith2', email='[email protected]', password='password')
u.save()
prof = UserProfile.create(user=u)
color = Color.create(100, 100, 100)
color.save()
prof.color = color
prof.save()
u = User.objects.create_user(username='jsmith3', email='[email protected]', password='password')
u.save()
prof = UserProfile.create(user=u)
color = Color.create(200, 200, 200)
color.save()
prof.color = color
prof.save()
project = Project.create('project-x')
project.save()
project.users.add(UserProfile.objects.get(user=User.objects.get(username='jsmith')))
project.users.add(UserProfile.objects.get(user=User.objects.get(username='jsmith2')))
project.users.add(UserProfile.objects.get(user=User.objects.get(username='jsmith3')))
project.save()
return HttpResponse('Successful database setup')
示例2: create_account
# 需要导入模块: from accounts.models import UserProfile [as 别名]
# 或者: from accounts.models.UserProfile import create [as 别名]
def create_account(request):
def render_page(user_exists=False):
params = {'user_exists': user_exists}
return render(request, 'accounts/create_account.html', params)
if request.method == 'POST':
print('creating account')
username = request.POST.get('username')
password = request.POST.get('password')
email = request.POST.get('email')
if User.objects.filter(username__iexact=username).exists() or User.objects.filter(email__iexact=email).exists():
return render_page(user_exists=True)
else:
user = User.objects.create_user(username, email, password)
profile = UserProfile.create(user)
profile.save()
return redirect('main.views.home')
else:
return render_page()