Search code examples
pythondjangodjango-taggit

How can I have django-taggit tags deleted when there are no more objects attached to them?


I think the title says it. Many tags are created and deleted but they still exist even when no more objects are using them.

Is there a way to make it check upon save and delete unused tags?


Solution

  • The only technique I can think of would be to attach a custom pre_delete signal handler to every taggable model that checks if it was the last model with any particular tag. In the event that it is, delete that tag.