Question

I have 2 models: reviews and product:

class Review(models.Model):
    user = models.ForeignKey(User, related_name="user_blog")
    tag = TaggableManager() 
    product = models.ForeignKey(Product)
    review_text = models.TextField() 
    created = models.DateTimeField(auto_now=True, auto_now_add=False)
    updated = models.DateTimeField(auto_now=True, auto_now_add=True)
    hashtag = models.ForeignKey(Hashtag)

class Product(models.Model):
    name = models.CharField(max_length=500)

I want to filter the all tags related to a product, which I'm doing like this:

review = Review.objects.get(product=prod.id)  
for tag in review.tag:
    print tag.name

But I'm getting:

 Traceback (most recent call last):
  File "<console>", line 1, in <module>
TypeError: '_TaggableManager' object is not iterable
Was it helpful?

Solution

Manager is not iterable. Use all method to get an iterable QuerySet:

for tag in review.tag.all():
    print tag.name
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top