If Statement Problems with For Loop

I am new to Django, and is facing some problem

I have categories for say computer programing, computer hardware, and website development. Under each category a candidate has to study 3 books. Book One, Book Two, and Book Three.

To list all the categories, and their respective books in Django, I am using if statement, with for loop. I have tried, both for loop within the if statement, and vice versa, however failed.

I want to show the website development (category) books (book one to book three) if the website development is satisfied, and if the computer programing is satisfied, the list should show the computer programing books.

May you please help me how to get it done.

Thanksenter image description here

{% for name in bk_name %}
<ul class="list-group list-group-horizontal">
    {% if cat_name=="website development" %}
         <li class="list-group-item"> {{ name.book_title }} </li>
    {% endif %}
</ul>


{% endfor %}
<ul class="list-group list-group-horizontal">
    {% if cat_name=="Computer Programming" %}
         {% for name in bk_name % }
             <li class="list-group-item"> {{ name.book_title }} </li>
         {% endfor %}
    {% endif %}
</ul>

Remember you are looping through for name in bk_name, so you need to reference name to get to the curent loop's name properties.

Assuming bk_name is a collection of book objects and therefore name is a book object that also has a cat_name property, then you just need something like this:

{% for name in bk_name %}
    {% if name.cat_name == "website_development" %}
Back to Top