Sidharth Sidharth -4 years ago 53
Python Question

How to Get Categories of Django Osacr product?

I have a list of product. I want to get the category(categories) it is associated with.
What i have done is :

pro = [] #holds list of all the products
for p in pro:
for procat in p.get_categories():

but it returns with Error:

'ManyRelatedManager' object is not iterable

I got the method from here DJANGO OSCAR

Answer Source

To get an iterable object for the ManyToManyField "categories" as specified in the docs, you can try to call .all() method, e.g.:

for procat in p.get_categories().all():
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download