kurdebalans
kurdebalans

Reputation: 27

DJANGO how to make boolean field (True/False) display "Available / Not Available" in View?

My code in Django:

class Product(models.Model):

available = models.BooleanField(default=True)

My code in HTML:

{% for product in products %}
    <li>
    <a href="{% url 'product_detail' product.id %}">
        {{ product.name }}{{ product.price }}{{ product.available }}
    </a>
    </li>
{% endfor %}

Upvotes: 0

Views: 742

Answers (1)

AKX
AKX

Reputation: 168957

Use the built-in yesno filter.

{{ product.available|yesno:"Available,Not Available" }}

Upvotes: 5

Related Questions