Пример #1
0
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})
Пример #2
0
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})
Пример #3
0
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})
Пример #4
0
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)