Ejemplo n.º 1
0
def beverage_detail(request, beer_id):
    btype = get_object_or_404(models.Beverage, id=beer_id)

    form = forms.BeverageForm(instance=btype)
    if request.method == 'POST':
        form = forms.BeverageForm(request.POST, instance=btype)
        if form.is_valid():
            btype = form.save()
            new_image = request.FILES.get('new_image')
            if new_image:
                pic = models.Picture.objects.create()
                pic.image.save(new_image.name, new_image)
                pic.save()
                btype.picture = pic
                btype.save()

            messages.success(request, 'Beer type updated.')
            return redirect('kegadmin-beverages')
        else:
            messages.error(request, 'Please correct the error(s) below.')

    context = {}
    context['beer_type'] = btype
    context['form'] = form
    return render(request, 'kegadmin/beer_type_detail.html', context=context)
Ejemplo n.º 2
0
def beverage_add(request):

    form = forms.BeverageForm()
    if request.method == 'POST':
        form = forms.BeverageForm(request.POST)
        if form.is_valid():
            btype = form.save()
            new_image = request.FILES.get('new_image')
            if new_image:
                pic = models.Picture.objects.create()
                pic.image.save(new_image.name, new_image)
                pic.save()
                btype.picture = pic
                btype.save()

            messages.success(request, 'Beer type added.')
            return redirect('kegadmin-beverages')

    context = {}
    context['beer_type'] = 'new'
    context['form'] = form
    return render(request, 'kegadmin/beer_type_add.html', context=context)
Ejemplo n.º 3
0
def beverage_add(request):

    form = forms.BeverageForm()
    if request.method == "POST":
        form = forms.BeverageForm(request.POST)
        if form.is_valid():
            btype = form.save()
            new_image = request.FILES.get("new_image")
            if new_image:
                pic = models.Picture.objects.create()
                pic.image.save(new_image.name, new_image)
                pic.save()
                btype.picture = pic
                btype.save()

            messages.success(request, "Beer type added.")
            return redirect("kegadmin-beverages")

    context = {}
    context["beer_type"] = "new"
    context["form"] = form
    return render(request, "kegadmin/beer_type_add.html", context=context)