'Add tags to object, working around duplicate tag issues.'

def safe_add_tags(self, tags, tag_type, tag_relation):

    for tag in self.deduped_tags(tags):
        existing_tags = tag_type.objects.filter(name=tag)
        tag_count = existing_tags.count()
        assert (tag_count <= 1)
        if (tag_count == 1):
            dt = existing_tags.get()
        else:
            dt = tag_type.objects.create(name=tag)
        tag_relation.add(dt)
