내 위시리스트에 대한 코드를 사용하고 있습니다. 내 사이트에 표시하고자하는 위시리스트의 제품이 필요하지 않습니다. 다양한 방법을 시도했지만 세션이이 작업을 수행 할 것이라고 생각합니다. 약간의 도움을주십시오.어떻게 장고보기에서 세션의 lenth을 얻을 수
어떻게 그렇게 할 수 있습니까?
@never_cache
def wishlist(request, template="shop/wishlist.html"):
"""
Display the wishlist and handle removing items from the wishlist and
adding them to the cart.
"""
skus = request.wishlist
error = None
if request.method == "POST":
to_cart = request.POST.get("add_cart")
add_product_form = AddProductForm(request.POST or None,
to_cart=to_cart,request=request)
if to_cart:
if add_product_form.is_valid():
request.cart.add_item(add_product_form.variation, 1,request)
recalculate_discount(request)
message = _("Item added to cart")
url = "shop_cart"
else:
error = add_product_form.errors.values()[0]
else:
message = _("Item removed from wishlist")
url = "shop_wishlist"
sku = request.POST.get("sku")
if sku in skus:
skus.remove(sku)
if not error:
info(request, message)
response = redirect(url)
set_cookie(response, "wishlist", ",".join(skus))
return response
# Remove skus from the cookie that no longer exist.
published_products = Product.objects.published(for_user=request.user)
f = {"product__in": published_products, "sku__in": skus}
wishlist = ProductVariation.objects.filter(**f).select_related(depth=1)
wishlist = sorted(wishlist, key=lambda v: skus.index(v.sku))
context = {"wishlist_items": wishlist, "error": error}
response = render(request, template, context)
if len(wishlist) < len(skus):
skus = [variation.sku for variation in wishlist]
set_cookie(response, "wishlist", ",".join(skus))
return response
이 연료 소모량을 추가하는 데 사용됩니다 나는 위시리스트에있는 제품을 제거합니다. –
세션 중에 제품 수가 필요합니다. –
어떤 세션입니까? 쿠키를 사용하고 있는데 세션이 아닌 것 같습니다. –