'Return Tag objects by key, by category, by object (it is
stored on) or with a combination of those criteria.
Attrs:
key (str, optional): The Tag\'s key to search for
category (str, optional): The Tag of the attribute(s)
to search for.
obj (Object, optional): On which object the Tag to
search for is.
tagtype (str, optional): One of None (normal tags),
"alias" or "permission"
global_search (bool, optional): Include all possible tags,
not just tags on this object
Returns:
tag (list): The matching Tags.'

def get_tag(self, key=None, category=None, obj=None, tagtype=None, global_search=False):

    global _Tag
    if (not _Tag):
        from evennia.typeclasses.models import Tag as _Tag
    dbmodel = self.model.__dbclass__.__name__.lower()
    if global_search:
        query = [('db_tagtype', tagtype), ('db_model', dbmodel)]
        if obj:
            query.append(('id', obj.id))
        if key:
            query.append(('db_key', key))
        if category:
            query.append(('db_category', category))
        return _Tag.objects.filter(**dict(query))
    else:
        query = [('tag__db_tagtype', tagtype), ('tag__db_model', dbmodel)]
        if obj:
            query.append((('%s__id' % self.model.__name__.lower()), obj.id))
        if key:
            query.append(('tag__db_key', key))
        if category:
            query.append(('tag__db_category', category))
        return [th.tag for th in self.model.db_tags.through.objects.filter(**dict(query))]
