如何为 django-oscar 添加 mini_wishlist?

How to add mini_wishlist for django-oscar?

我正在使用 django-oscar 为电子商务网站工作。 我对愿望清单有疑问。我想在导航栏上添加 mini_whislist。看起来像奥斯卡的 basket_quick.

我试过这个,但它只适用于心愿单部分。

{% if wishlists %}
   {% for wishlist in wishlists %} 
       <span class="text-muted b">{{ wishlist.name }}</span>
       <span class="text-muted b">{{ wishlist.lines.count }}</span>
   {% endfor %}
{% else %}
    <img src="{% static "images/topview.png" %}">
    <span class="p-2 text-muted b">EMPTY</span>
{% endif %}

如何让它出现在每个页面上?

一个想法是将你为此功能编写的所有 html 放入一个 HTML 文件中,然后在 layout.html 中使用 {% include 'your_file.html' %},它不会放入 base.html 是个好主意,因为仪表板也扩展了相同的基本模板。

此外,请注意,您必须在 checkout/layout.html 中执行相同的操作,因为它们有单独的结帐页面布局。

在客户应用程序中创建上下文处理器...
context_processors.py

def wishlists(request):
    if not (request.user and request.user.is_authenticated):
        return {}
    return {
        'wishlists': request.user.wishlists.all()
    }

并将其放入设置文件

TEMPLATE_CONTEXT_PROCESSORS = (

    'customer.context_processors.wishlists',
)

然后你可以在任何地方使用心愿单