Yasinautilus
Yasinautilus

Reputation: 25

How to only render Products with a certain title?

So I was finally able to render my products on the main page. But as I try to list the Products by their brand name (typed into "title" when creating a product in the dashboard), I therefore want to only render certain products with a certain title name. My guess was to do it this way (lets say the title name I typed in was uniqlo):

        {% for product in products %}
                    {% render_product product.product_title.uniqlo %}
        {% endfor %}

but unfortunately nothing is rendered. I tried many other possibilities but no luck so far.

I also tried to find out how the product was saved by looking into shell, but whatever from..import.. I put in, Product.objects.all() results in Product is not defined.

Upvotes: 2

Views: 147

Answers (1)

shad0w_wa1k3r
shad0w_wa1k3r

Reputation: 13372

The ask is not clear. Do you want to always filter on that uniqlo title? Or is it for some specific (landing / main) page?

In any case, a simple way would be (based on what you've already tried) -

{% for product in products %}
    {% if 'uniqlo' in product.title %}
        {% render_product product %}
    {% endif %}
{% endfor %}

Also, for the shell import, try

from oscar.core.loading import get_model
Product = get_model('catalogue', 'Product')

If you're trying to filter for the title only in your landing / main page, you can filter the products in the view itself, before passing it to the template -

products = Product.objects.filter(title__icontains='uniqlo')

Upvotes: 2

Related Questions