'Return Attribute objects by key, by category, by value, by
strvalue, by object (it is stored on) or with a combination of
those criteria.
Attrs:
key (str, optional): The attribute\'s key to search for
category (str, optional): The category of the attribute(s)
to search for.
value (str, optional): The attribute value to search for.
Note that this is not a very efficient operation since it
will query for a pickled entity. Mutually exclusive to
`strvalue`.
strvalue (str, optional): The str-value to search for.
Most Attributes will not have strvalue set. This is
mutually exclusive to the `value` keyword and will take
precedence if given.
obj (Object, optional): On which object the Attribute to
search for is.
attrype (str, optional): An attribute-type to search for.
By default this is either `None` (normal Attributes) or
`"nick"`.
Returns:
attributes (list): The matching Attributes.'

def get_attribute(self, key=None, category=None, value=None, strvalue=None, obj=None, attrtype=None):

    dbmodel = self.model.__dbclass__.__name__.lower()
    query = [('attribute__db_attrtype', attrtype), ('attribute__db_model', dbmodel)]
    if obj:
        query.append((('%s__id' % self.model.__name__.lower()), obj.id))
    if key:
        query.append(('attribute__db_key', key))
    if category:
        query.append(('attribute__db_category', category))
    if strvalue:
        query.append(('attribute__db_strvalue', strvalue))
    elif value:
        query.append(('attribute__db_value', value))
    return [th.attribute for th in self.model.db_attributes.through.objects.filter(**dict(query))]
