@classmethod
def from_row(cls, row, select_related=None):
    """
        Instantiate a model instance, given a database row.
        """
    select_related = select_related or []
    item = {}
    for related in select_related:
        if '__' in related:
            first_part, remainder = related.split('__', 1)
            model_cls = cls.__fields__[first_part].type_.to
            item[first_part] = model_cls.from_row(row, select_related=[
                remainder])
        else:
            model_cls = cls.__fields__[related].type_.to
            item[related] = model_cls.from_row(row)
    for column in cls.Mapping.table.columns:
        if column.name not in item:
            col_type = cls.__fields__[column.name].type_
            value = row[column]
            if col_type.__name__ == 'ForeignKey':
                item[column.name] = col_type.to(pk=value, __pk_only__=True)
            else:
                item[column.name] = value
    return cls(**item)
