def get_dbattr(basemodel, attrstring):
    """
    get a database attribute for a string which may have multiple levels

    :param basemodel: top level model under which attrstring should be found
    :param attrstring: dotted notation attribute; dots allow traversal of multiple levels
    :return: bottom level attribute value
    """
    attrs = attrstring.split('.')
    thismodel = basemodel
    while len(attrs) > 1:
        thisattr = attrs.pop(0)
        thismodel = type(getattr(thismodel, thisattr))
    attr = attrs.pop(0)
    return getattr(thismodel, attr)
