def beverage_producer_detail(request, brewer_id): brewer = get_object_or_404(models.BeverageProducer, id=brewer_id) form = forms.BeverageProducerForm(instance=brewer) if request.method == 'POST': form = forms.BeverageProducerForm(request.POST, instance=brewer) if form.is_valid(): form.save() messages.success(request, 'Brewer updated.') return redirect('kegadmin-beverage-producers') context = {} context['brewer'] = brewer context['form'] = form return render(request, 'kegadmin/brewer_detail.html', context=context)
def beverage_producer_detail(request, brewer_id): brewer = get_object_or_404(models.BeverageProducer, id=brewer_id) form = forms.BeverageProducerForm(instance=brewer) if request.method == "POST": form = forms.BeverageProducerForm(request.POST, instance=brewer) if form.is_valid(): form.save() messages.success(request, "Brewer updated.") return redirect("kegadmin-beverage-producers") context = {} context["brewer"] = brewer context["form"] = form return render(request, "kegadmin/brewer_detail.html", context=context)
def beverage_producer_add(request): form = forms.BeverageProducerForm() if request.method == 'POST': form = forms.BeverageProducerForm(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, 'Brewer added.') return redirect('kegadmin-beverage-producers') context = {} context['brewer'] = 'new' context['form'] = form return render(request, 'kegadmin/brewer_add.html', context=context)
def beverage_producer_add(request): form = forms.BeverageProducerForm() if request.method == "POST": form = forms.BeverageProducerForm(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, "Brewer added.") return redirect("kegadmin-beverage-producers") context = {} context["brewer"] = "new" context["form"] = form return render(request, "kegadmin/brewer_add.html", context=context)