def pizzashop_add_pizza(request): form = PizzaForm() if request.method == 'POST': form = PizzaForm(request.POST, request.FILES) if form.is_valid(): pizza = form.save(commit=False) pizza.pizzashop = request.user.pizzashop pizza.save() return redirect(pizzashop_pizza) return render(request, 'pizzashop/add_pizza.html', {"form": form})
def pizzashop_edit_pizza(request, pizza_id): form = PizzaForm(instance=Pizza.objects.get(id=pizza_id)) if request.method == 'POST': form = PizzaForm(request.POST, request.FILES, instance=Pizza.objects.get(id=pizza_id)) if form.is_valid(): pizza = form.save() return redirect(pizzashop_pizza) return render(request, 'pizzashop/edit_pizza.html', {"form": form})
def pizzashop_add_pizza(request): form = PizzaForm() if request.method == "POST": form = PizzaForm(request.POST, request.FILES) if form.is_valid(): pizza = form.save(commit=False) #кладем пиццу в пиццерию pizza.pizzashop = request.user.pizzashop pizza.save() return redirect(pizzashop_home) return render(request, 'pizzashop/add_pizza.html', {'form': form})
def pizzashop_add_pizza(request): form = PizzaForm() if request.method == 'POST': form = PizzaForm(request.POST, request.FILES) if form.is_valid(): pizza = form.save(commit=False) # Добавление пиццы в пиццерию pizza.pizzashop = request.user.Pizzashop pizza.save() return redirect(pizzashop_pizza) context = { 'form': form, } return render(request, 'pizzashop/add_pizza.html', context)