In one of my models I have a categories field that is a manytomany configuration.
I was wondering how to get the following output in the template.
Category 1, Category 2, Category 3 and Category 4
So basically separate each category with a comma, apart from the last one that then gets replaced with a "and"
{% for category in myob.categories.all %}
{{ category }}
{% if not forloop.last %},{% else %} and {% endif %}
{% endfor %}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With