Home > front end >  How to display N number of Backward relationship in Django templates?
How to display N number of Backward relationship in Django templates?

Time:12-22

{% for category in categories %}
    {% for product in categories.product_set.all %}
        <h1> {{ product.name }} </h1>
    {% endfor %}
{% endfor %}

I want to show 10 products instead of all in template

CodePudding user response:

There is a slice filter that you can use in templates:

{% for category in categories %}
    {% for product in categories.product_set.all|slice:":10" %}
        <h1> {{ product.name }} </h1>
    {% endfor %}
{% endfor %}
  • Related