def search_in_category(request, category): category = category categories = category_fn() query = request.GET['q'] sort_form = SortForm() order = extract_filter_value(request.GET) products = Product.objects.filter(category=category).filter( product_name__icontains=query).order_by(order) paginator = Paginator(products, 1) page_number = request.GET.get('page') page_obj = paginator.get_page(page_number) context = { 'category': category, 'products': products, 'categories': categories, 'len': len(products), 'page_obj': page_obj, 'query': query, 'sort_form': SortForm(), 'order': order, } return render(request, 'category.html', context)
def category_view(request, category): category = category categories = category_fn() if request.method == 'GET': #products = Product.objects.filter(category=category) sort_form = SortForm() order = extract_filter_value(request.GET) products = Product.objects.filter(category=category).order_by(order) paginator = Paginator(products, 6) page_number = request.GET.get('page') page_obj = paginator.get_page(page_number) context = { 'category': category, 'products': products, 'categories': categories, 'len': len(products), 'page_obj': page_obj, 'sort_form': sort_form, 'order': order, } return render(request, 'category.html', context)
def get_context_data(self, **kwargs): query = self.request.GET.get('q') context = super().get_context_data(**kwargs) categories = category_fn() context['query'] = query context['categories'] = categories context['sort_form'] = SortForm() return context
def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context['categories'] = category_fn() context['products'] = self.products context['sort_form'] = SortForm() context['filter_form'] = ProductFilterForm() context['order'] = self.order page_number = self.request.GET.get('page') if self.products: paginator = Paginator(self.products, 8) context['paginator'] = paginator context['page_obj'] = paginator.get_page(page_number) context['is_paginated'] = True return context
def get_context_data(self, **kwargs): self.order = extract_filter_value(self.request.GET) context = super().get_context_data(**kwargs) context['categories'] = category_fn() products = Product.objects.order_by(self.order) images = ProductPicture.objects.all() context['products'] = products context['sort_form'] = SortForm() context['order'] = self.order self.page_number = self.request.GET.get('page') paginator = Paginator(products, 6) context['paginator'] = paginator context['page_obj'] = paginator.get_page(self.page_number) context['is_paginated'] = True return context