Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I delete unused tags ? #294

Closed
ghost opened this issue Mar 8, 2015 · 6 comments
Closed

How can I delete unused tags ? #294

ghost opened this issue Mar 8, 2015 · 6 comments

Comments

@ghost
Copy link

ghost commented Mar 8, 2015

I'm trying to delete unused tags in django, but I don't know how to do it, how can I do it?

@kurtrwall
Copy link

You could go into the database directly and delete them, or you could write a script that looks for tags in the taggit_tag table that aren't assigned. There are other ways too. I'm currently running into this.

@PaulMest
Copy link

Here is a simple way to delete tags which are not associated with anything:

from taggit.models import Tag

def remove_all_tags_without_objects():
    for tag in Tag.objects.all():
        if tag.taggit_taggeditem_items.count() == 0:
            print('Removing: {}'.format(tag))
            tag.delete()
        else:
            print('Keeping: {}'.format(tag))

@jdufresne
Copy link
Member

Thanks for reporting. This issue looks like a duplicate of #111. If you have additional information to add, please do so there.

@saileshkush95
Copy link

Here is a simple way to delete tags which are not associated with anything:

from taggit.models import Tag

def remove_all_tags_without_objects():
    for tag in Tag.objects.all():
        if tag.taggit_taggeditem_items.count() == 0:
            print('Removing: {}'.format(tag))
            tag.delete()
        else:
            print('Keeping: {}'.format(tag))

How to use this and where to use this?

@PaulMest
Copy link

@saileshkush95
You could put it inside a Custom Management Command.

@kurtrwall
Copy link

You could put it inside a Custom Management Command.

you might be able to hook into your database event system to trigger it as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants