Remove Dead Tags

Published on Sept. 21, 2009

I've noticed my django-tagging install has been giving a lot of empty entries when doing a lookup on a tag. Tonight I finally got around to looking at what was causing this. This is surely not the best way to do this, but at 12:00am on a weekday, well, I shouldn't be doing it in the first place... I first wanted to see what type of content was generating the error:

for item in TaggedItem.objects.all():
    try:
        print item.object
    except:
        print item.content_type_id

Now that I could see what was causing it (I had removed an app that used django-tagging, but it left the tags with empty pointers). Removing the empty tags was easy enough:

for item in TaggedItem.objects.all():
    try:
        print item.object
    except:
        item.delete()

No more hanging TaggedItems.



Tagged as: django

blog comments powered by Disqus

About This Page

This entry is from my tutorial section and was written on Sept. 21, 2009. It's been tagged with django.

Via Twitter

Just saw a large white parrot try to steal the clothing from someone's drying rack. (about 2 weeks, 5 days ago)

Related Readings

Book Book Book Book