def post(self, request, *args, **kwargs): form = OrderForm(data=request.POST) if form.is_valid(): self.product_order = form.save() if self.request.user.is_authenticated: self.product_order.user = self.request.user self.product_order.save() self.order() return redirect('product_list') return redirect('basket_list')
def get_context_data(self, *, object_list=None, **kwargs): if not self.request.session.session_key: self.request.session.save() session = Session.objects.get(session_key=self.request.session.session_key) context = super().get_context_data(object_list=object_list, **kwargs) context['cart_total'] = Cart.get_cart_total(session=session) context['form'] = OrderForm() context['cart'] = context['cart'].filter(session=session) return context
def post(self, request): my_dict = request.session.get('my_dict') form = OrderForm(data=request.POST) if form.is_valid(): order = form.save() for i in my_dict: cart = Cart.objects.get(pk=i) product = ProductOrder.objects.create(product=cart.product, order=order, quantity=cart.quantity) if request.user.is_authenticated: order.user = request.user order.save() request.session.pop('my_dict') return redirect('product-list') else: return render(request, 'cart/index.html', context={ 'form': form, 'cart': my_dict })
def post(self, request, *args, **kwargs): session = request.session.get('basket', []) basket = Basket.objects.filter(pk__in=session) form = OrderForm(data=request.POST) if form.is_valid(): name = form.cleaned_data.get('name') adress = form.cleaned_data.get("adress") phone = form.cleaned_data.get('phone') order = Order.objects.create(name=name, adress=adress, phone=phone, user=None) for x in basket: qty = x.product_qty product = x.product_b ProductOrder.objects.create(order=order, product=product) basket.delete() request.session['basket'] = [] return redirect('webapp:index') else: return render(request, 'webapp:basket.html', {'form': form})
def get_context_data(self, *, object_list=None, **kwargs): context = super().get_context_data(object_list=object_list, **kwargs) context['cart_total'] = Cart.get_cart_total(ids=self.get_cart_ids()) context['form'] = OrderForm() return context
def get_context_data(self, *, object_list=None, **kwargs): context = super().get_context_data(object_list=object_list, **kwargs) context['all'] = Basket.get_cart_total( session_key=self.get_session_key()) context['form'] = OrderForm() return context
def post(self, request, *args, **kwargs): form = OrderForm(data=request.POST) if form.is_valid(): return self.form_valid(form) else: return self.form_invalid(form)
def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context['sum'] = self.get_sum_basket() context['form'] = OrderForm() return context
def get_context_data(self, *, object_list=None, **kwargs): context = super().get_context_data(object_list=None, **kwargs) context['form'] = OrderForm() return context