0

I am using the django taggit to add tags to all bids.

My bid model is as follows:

class Bid(models.Model):
    tags = TaggableManager()

How can I remove a particular tag from all bids who have that tag?

I was going to do the following:

Let's say I want to remove the tag "delicious" from all bids with that tag:

bids = Bid.objects.filter(tags__name__in=["delicious"])
bids.tags.remove("delicious")

Is that the correct way to do so?

Thanks!

jewelwast
  • 2,657
  • 4
  • 17
  • 13

1 Answers1

0

No, you can't do this. In your example, bids is a queryset and attribute tags is not available on queryset.

You have defined attribute tags on class Bid, so it is available on any instance of Bid. But,it would not be available on the queryset.

For removing tag delicious on all the bids in your example:

for bid in bids:
    bid.tags.remove("delicious")
Akshar Raaj
  • 14,231
  • 7
  • 51
  • 45