Skip to content
Advertisement

How do I display my products by certain category

So I am making an ecom site, and I am using Django. I am quite new and I am using a tutorial but have stepped off touch with it as I want to have 2 categories and maybe more on my website in the future. I want to be able to display them by their category, and I asked for help around my discord server and some people have tried to help and it does go through all my products however I have an if statement and that if statement gets ignored

So can anyone show me a way to display products with their category set as Specials only? Or hatbox only?

Store.Html

JavaScript

views.py

JavaScript

models.py

JavaScript

admin.py

JavaScript

Advertisement

Answer

The if statement in the code won’t work as the products inside {% if products.categories == Hatbox %} does not have any categories since its not a single category object. The if statement is also missing quotes around Hatbox. Try this below:

Views

JavaScript

store.html

JavaScript

Have a read add the docs here and some StackOverflow links here and here for related_names.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement