Last active
March 13, 2017 13:24
-
-
Save fredkingham/57dbee1b3456f8d8311d826316c7ff4f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from opal.models import Tagging, Episode | |
from django.db.models import Count | |
dupes = Tagging.objects.values('value', 'episode', 'user').annotate(Count('id')).order_by().filter(id__count__gt=1) | |
# handle non mine | |
for dupe in dupes: | |
episode = Episode.objects.get(id=dupe["episode"]) | |
print "episode {}".format(episode) | |
tags = episode.tagging_set.filter(value=dupe["value"], user=dupe["user"]) | |
tags = tags.exclude(id=tags.last().id) | |
tags.delete() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment