jazzband / django-taggit

Simple tagging for django
https://django-taggit.readthedocs.io
BSD 3-Clause "New" or "Revised" License
3.33k stars 622 forks source link

Helper to merge identical case-insensitive tags #470

Open geoffroy-noel-ddh opened 7 years ago

geoffroy-noel-ddh commented 7 years ago

I changed TAGGIT_CASE_INSENSITIVE to True in my settings file. But the taggit_tag table has already been populated with case-insensitive duplicates on my production database. This situation also causes python errors or tags to stick when saving django models which contain two duplicate tags (e.g. MyTag and mytag). Fair enough this situation shouldn't occur in the first place so that's not really a bug.

However it would be nice to provide an API function and a django manage.py command to merge duplicate tags and references. This could then be easily called from my own database migration scripts and fixed automatically on various instances that currently need this change.

KayleeTheMech commented 5 years ago

For me the issue is not just case-wise duplicates, also people might be using different terms for the same thing or just different ways to write (CamelCase, snake-case, Space case ... etc, or just common typos)

I'd love a functionality where I could turn a Tag into a DuplicateTag object.

Something like:

class DuplicateTag(TagBase):
    duplicate_of:Tag 
    class Meta:
        verbose_name = _("Tag")
        verbose_name_plural = _("Tags")
        app_label = "taggit"

Where the duplicate_of field just refers to the Tag which should be chosen instead of that one.

Example Case: The tag people are supposed to use would be "Cyber Hopping". In reality all these will be also used: CyberHopping, Cyberhopping, Cyber-hopping, Cyber hopping....

Being able to mark/transform the latter Tags as/into a duplicate of another would help greatly to keep things clean.

This is just an idea, if that's appreciated by the contributors, or if they have/want/plan a different solution please let me know. I might just start to toy around trying to put this one into code at some point.

alper commented 5 years ago

I would like a generic Tag:mergeInto(Tag) function that initially just nukes the source tag and reparents all the content on the target tag. That would save me from having to write and test such a function myself.