Featured products on mezzanine project homepage

217 Views Asked by At

I am working on an implementation of an online shop using cartridge & mezzanine. I would like to include a "featured products" section using a category from cartridge's shop (product_category). I have created a test category, populated it with entries and am trying to view it from the homepage but it doesn't return anything. What should i be doing instead?

index.html

{% with category as "featured" %}
{% for product in products.object_list %}

(just using the category.html product display html for now)

views.py

def index(request):
    products = Product.objects.all()
    context = {'products': products}
    return render(request, 'index.html', context)
1

There are 1 best solutions below

0
On

Your code in index.html:

{% with category as "featured" %}

means treat variable category as string literals (are you sure that this is what you want?), so you will unable to use variable featured after this statement.

Values enclosed in single quotes (') or double quotes (") are treated as string literals, while values without quotes are treated as template variables. (Django docs)

Next, according to your code, you have products variable (and this is QuerySet) in your context, so value products.object_list will give nothing, as a QuerySet object do not have object_list attribute. Maybe what you want in this line is

{% for product in products %}

You may publish more code to clarify situation.