how to return a product category name

28 views
Skip to first unread message

femi ogundayo

unread,
Nov 23, 2015, 6:22:59 AM11/23/15
to django-oscar
Hi i would like to return the product category name on a template so far i have tried using {{ product.categories.name}} but it keeps returning 'None'  on the template page. Any help?

Thanks 

Qijiong Jiang

unread,
Nov 23, 2015, 10:35:36 AM11/23/15
to django...@googlegroups.com
product <=manyTOmany=> categories relationship by default
Have you tried this one(assuming that you want to show the first category of the product)?
{% with category = product.categoies.all.0 %}
  {{ category.name }}
{% endwith %}

On Mon, Nov 23, 2015 at 12:22 PM, femi ogundayo <coco...@gmail.com> wrote:
Hi i would like to return the product category name on a template so far i have tried using {{ product.categories.name}} but it keeps returning 'None'  on the template page. Any help?

Thanks 

--
https://github.com/tangentlabs/django-oscar
http://django-oscar.readthedocs.org/en/latest/
https://twitter.com/django_oscar
---
You received this message because you are subscribed to the Google Groups "django-oscar" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-oscar...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-oscar.
To view this discussion on the web, visit https://groups.google.com/d/msgid/django-oscar/98b1f1ab-5666-4170-a9cb-f51039d522c1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages