'Return objects having tags with a given key or category or
combination of the two.
Args:
key (str, optional): Tag key. Not case sensitive.
category (str, optional): Tag category. Not case sensitive.
tagtype (str or None, optional): \'type\' of Tag, by default
this is either `None` (a normal Tag), `alias` or
`permission`.
Returns:
objects (list): Objects with matching tag.'

@returns_typeclass_list
def get_by_tag(self, key=None, category=None, tagtype=None):

    dbmodel = self.model.__dbclass__.__name__.lower()
    query = [('db_tags__db_tagtype', tagtype), ('db_tags__db_model', dbmodel)]
    if key:
        query.append(('db_tags__db_key', key.lower()))
    if category:
        query.append(('db_tags__db_category', category.lower()))
    return self.filter(**dict(query))
