How to get to a class model field through a ManyToMany field in another class

14 views
Skip to first unread message

Александр Мусаров

unread,
Aug 10, 2015, 11:32:02 AM8/10/15
to Django users
I'm having  two model classes Product and Category, on the one hand the Product class has a ManyToMany field ( product_categories ) which lists all the categories, a product instance may belong to, on the other hand the Category class has the category_slug field. The question is - is there any way to get to the Category.category_slug field from the Product.product_categories field in the following method
       @models.permalink
           def get_absolute_url(self):
           return ('catalog_product', (), {'category_slug' : self.product_categories.category_slug, 'product_slug': self.product_slug})   ( this way of getting to it gives the: AttributeError at /catalog/smartphony/   'ManyRelatedManager' object has no attribute 'category_slug'  )
Reply all
Reply to author
Forward
0 new messages