def product_detail(request, id, slug): product = get_object_or_404(Product, id=id, slug=slug, available=True) cart_product_form = CartAddProductForm() return render(request, 'product_detail.html', { 'product': product, 'cart_product_form': cart_product_form })
def detalle_producto(request, id, slug): producto = get_object_or_404(Producto, id=id, slug=slug, disponible=True) cart_product_form = CartAddProductForm() if producto: try: histdia = Historial.objects.filter(producto=producto, usuario=request.user) if not histdia: guardahist = Historial() guardahist.producto = producto guardahist.usuario = request.user guardahist.save() except Exception: pass if settings.USE_REDIS: r = Recommender() productos_recomendados = r.productos_sugeridos_para([producto], 4) print("Productos a buscar recomendacion {}".format(producto)) else: productos_recomendados = None return render( request, 'ecommerce/producto/detalle.html', { 'producto': producto, 'cart_product_form': cart_product_form, 'productos_recomendados': productos_recomendados })
def cart_detail(request): cart = Cart(request) for item in cart: item['update_quantity_form'] = CartAddProductForm( initial={ "quantity": item['quantity'], 'update': True }) return render(request, 'cart/shopping_cart.html', locals())
def cart_add(request, product_id): cart = Cart(request) product = get_object_or_404(Product, id=product_id) form = CartAddProductForm(request.POST) if form.is_valid(): cd = form.cleaned_data cart.add(product=product, quantity=cd['quantity'], update_quantity=cd['update']) return redirect('cart:cart_detail')
def home(request): template = 'home.html' cart_product_form = CartAddProductForm() queryset = Product.objects.all().order_by('-created_on').active() context = { 'object_list': queryset, 'cart_product_form': cart_product_form, } return render(request, template, context)
def products(request): count = settings.ONE_PAGE_PRODUCTS_COUNT productses = Products.objects.select_related('category').all()[0:count] categories = ProductCategory.objects.all() cart_product_form = CartAddProductForm() context = { 'productses': productses, 'categories': categories, 'cart_product_form': cart_product_form } return render(request, 'main/product_detail.html', context=context)
def single_product(request, products_id): try: product = Products.objects.select_related('category').get(pk=products_id) categories = ProductCategory.objects.all() cart_product_form = CartAddProductForm() context = { 'product': product, 'categories': categories, 'cart_product_form': cart_product_form } return render(request, 'main/single_product.html', context=context) except Products.DoesNotExist: raise Http404
def product_detail(request, id, slug): language = request.LANGUAGE_CODE product = get_object_or_404( Product, id=id, translations__language_code=language, translations__slug=slug, available=True ) cart_product_form = CartAddProductForm() context = { 'product': product, 'cart_product_form': cart_product_form } return render(request, 'shop/product/detail.html', context)
def product_detail_view(request, slug, *args, **kwargs): queryset = Product.objects.all() cart_product_form = CartAddProductForm() instance = get_object_or_404(Product, slug=slug, active=True) if instance is None: raise Http404("Product doesn't exist") similar_products = instance.tags.similar_objects()[:2] context = { 'object': instance, 'object_list': queryset, 'cart_product_form': cart_product_form, 'similar_products': similar_products, } return render(request, "products/detail.html", context)
class ProductDetailSlugView(DetailView): queryset = Product.objects.all() template_name = "products/detail.html" cart_product_form = CartAddProductForm() def get_object(self, *args, **kwargs): request = self.request slug = self.kwargs.get('slug') #instance = get_object_or_404(Product, slug=slug, active=True) try: instance = Product.objects.get(slug=slug, active=True) except Product.DoesNotExist: raise Http404("Not found..") except Product.MultipleObjectsReturned: qs = Product.objects.filter(slug=slug, active=True) instance = qs.first() except: raise Http404("Uhhmmm ") return instance
def cart_detail(request): cart = Cart(request) for item in cart: item['update_quantity_form'] = CartAddProductForm( initial={ 'quantity': item['quantity'], 'update': True }) if settings.USE_REDIS: r = Recommender() cart_products = [item['product'] for item in cart] if cart_products: productos_recomendados = r.productos_sugeridos_para(cart_products, max_results=4) else: productos_recomendados = None else: productos_recomendados = None return render(request, 'cart/detail.html', { 'cart': cart, 'productos_recomendados': productos_recomendados })
def product_detail(request,id,slug): product = get_object_or_404(Product,id=id,slug=slug,available=True) cartaddproductform = CartAddProductForm() return render(request,'web/detail.html',locals())
def product_list_view(request, cat_filter=None, name_ascend=None, name_descend=None, price_ascend=None, price_descend=None, manu_filter=None, tag_slug=None): queryset = Product.objects.all().order_by('-created_on') cart_product_form = CartAddProductForm() tagv = [] for all_tags in queryset: for each_tag in all_tags.tags.order_by('name'): tagv.append(each_tag) uniq = Counter(tagv) cat_filters = Product.objects.values_list('category', flat='true') cat_filt = [] for cat in cat_filters: cat_filt.append(cat) filt = Counter(cat_filt) manu_filters = Product.objects.values_list('manufacturer', flat='true') manu_filt = [] for manu in manu_filters: manu_filt.append(manu) manufacturer = Counter(manu_filt) tag = None if tag_slug: tag = get_object_or_404(Tag, slug=tag_slug) queryset = queryset.filter(tags__name__in=[tag]).distinct() if cat_filter: queryset = queryset.category_filter(cat_filter) # print(manu_filter) # queryset = queryset.manufacturer_filter('Samsung') # print("manu queries", queryset) if manu_filter: queryset = queryset.manufacturer_filter(manu_filter) print("manu queries", queryset) if name_ascend: queryset = queryset.order_by('title') if name_descend: queryset = queryset.order_by('-title') if price_ascend: queryset = queryset.order_by('price') if price_descend: queryset = queryset.order_by('-price') paginator = Paginator(queryset, 9) page = request.GET.get('page') try: queryset = paginator.page(page) except PageNotAnInteger: queryset = paginator.page(1) except EmptyPage: queryset = paginator.page(paginator.num_pages) context = { 'object_list': queryset, 'cart_product_form': cart_product_form, 'tag': tag, 'page': page, 'uniq': uniq, 'filt': filt, 'manufacturer': manufacturer } return render(request, "products/list.html", context)