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' )
-- @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' )
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/72e99268-4b86-4d6a-9c52-8774a3942a98%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment