def pizzashop_sign_up(request): user_form = UserForm pizzashop_form = PizzaShopForm if request.method == 'POST': user_form = UserForm(request.POST) pizzashop_form = PizzaShopForm(request.POST, request.FILES) if user_form.is_valid() and pizzashop_form.is_valid(): new_user = User.objects.create_user(**user_form.cleaned_data) new_pizzashop = pizzashop_form.save(commit=False) new_pizzashop.owner = new_user new_pizzashop.save() login(request, authenticate( username = user_form.cleaned_data['username'], password = user_form.cleaned_data['password'] )) return redirect(pizzashop_home) return render(request, 'pizzashopapp/sign_up.html', #формы передаём 3тьим параметром { 'user_form' : user_form, 'pizzashop_form' : pizzashop_form })
def pizzashop_sign_up(request): user_form = UserForm pizzashop_form = PizzaShopForm #в первый раз передает изначальные данные а во второй раз те что задал клиент if request.method == "POST": user_form = UserForm(request.POST) pizzashop_form = PizzaShopForm(request.POST, request.FILES) # если все данные введены верно то создает нового пользователя if user_form.is_valid() and pizzashop_form.is_valid(): new_user = User.objects.create_user(**user_form.cleaned_data) new_pizzashop = pizzashop_form.save(commit=False) new_pizzashop.owner = new_user new_pizzashop.save login( request, authenticate(username=user_form.cleaned_data['username'], password=user_form.cleaned_data['password'])) return redirect(pizzashop_home) return render(request, 'pizzashop/sign_up.html', { 'user_form': user_form, 'pizzashop_form': pizzashop_form })
def pizzashop_sign_up(request): user_form = UserForm() pizzashop_form = PizzaShopForm() return render(request, 'pizzashop/sign_up.html', { 'user_form': user_form, 'pizzashop_form': pizzashop_form })
def pizzashop_account(request): user_form = UserFormForEdit(instance=request.user) pizzashop_form = PizzaShopForm(instance=request.user.pizzashop) if request.method == "POST": user_form = UserFormForEdit(request.POST, instance=request.user) pizzashop_form = PizzaShopForm(request.POST, request.FILES, instance=request.user.pizzashop) if user_form.is_valid() and pizzashop_form.is_valid(): user_form.save pizzashop_form.save return render(request, 'pizzashopapp/account.html', { 'user_form': user_form, 'pizzashop_form': pizzashop_form })
def pizzashop_sign_up(request): user_form = UserForm() pizzashop_form = PizzaShopForm() if request.method == "POST": user_form = UserForm(request.POST) pizzashop_form = PizzaShopForm(request.POST, request.FILES) if user_form.is_valid() and pizzashop_form.is_valid(): new_user = User.objects.create_user(**user_form.cleaned_data) new_pizzashop = pizzashop_form.save(commit=False) new_pizzashop.owner = new_user new_pizzashop.save() login( request, authenticate(username=user_form.cleaned_data['username'], password=user_form.cleaned_data['password'])) return redirect('pizzapp:pizzashop-home') return render(request, 'pizzashop/sign_up.html', { 'user_form': user_form, 'pizzashop_form': pizzashop_form })
def pizzashop_sign_up(request): user_form = UserForm() pizzashop_form = PizzaShopForm() if request.method == 'POST': user_form = UserForm(request.POST) pizzashop_form = PizzaShopForm(request.POST, request.FILES) if user_form.is_valid() and pizzashop_form.is_valid(): new_user = User.objects.create_user(**user_form.cleaned_data) new_pizzashop = pizzashop_form.save(commit=False) # передаем нового владельца new_pizzashop.owner = new_user new_pizzashop.save() login(request, authenticate( username=user_form.cleaned_data['username'], password=user_form.cleaned_data['password'], )) return redirect(pizzashop_home) context = { 'user_form': user_form, 'pizzashop_form': pizzashop_form, } return render(request, 'pizzashop/sign_up.html', context)
def sign_up(req): user_form = UserForm() pizza_shop_form = PizzaShopForm() if req.method == "POST": user_form = UserForm(req.POST) pizza_shop_form = PizzaShopForm(req.POST, req.FILES) if user_form.is_valid() and pizza_shop_form.is_valid(): new_user = User.objects.create_user(**user_form.cleaned_data) new_pizzashop = pizza_shop_form.save(commit=False) new_pizzashop.owner = new_user new_pizzashop.save() login( req, authenticate( username=user_form.cleaned_data["username"], password=user_form.cleaned_data["password"], ), ) return redirect(back_home) return render( req, "pizzashopapp/sign_up.html", {"user_form": user_form, "pizza_shop_form": pizza_shop_form}, )
def pizzashop_account(request): user_form = UserFormForEdit(instance=request.user) pizzashop_form = PizzaShopForm(instance=request.user.Pizzashop) if request.method == 'POST': user_form = UserFormForEdit(request.POST, instance=request.user) pizzashop_form = PizzaShopForm(request.POST, request.FILES, instance=request.user.Pizzashop) if user_form.is_valid() and pizzashop_form.is_valid(): user_form.save() pizzashop_form.save() context = { 'user_form': user_form, 'pizzashop_form': pizzashop_form } return render(request, 'pizzashop/account.html', context)