Dennis Gathagu
Dennis Gathagu

Reputation: 105

How do you filter django-oscar products to show only products from a specific category?

I'm quite new to django-oscar and i'm trying to figure out how i can create a queryset that only returns products with a certain category on a section in my template, for instance all products with the category 'electronics'.How can i go about this?

Upvotes: 0

Views: 882

Answers (1)

1john
1john

Reputation: 46

Might be easiest to start with the category and then get all the category's products:

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

cat = Category.objects.get(name='electronics')

prods = cat.product_set.all()

Then add prods to your response and use it in your template.

Upvotes: 3

Related Questions