'Load document and children from database and create properties
from fields'

def load_from_db(self):

    if ((not getattr(self, u'_metaclass', False)) and self.meta.issingle):
        single_doc = frappe.db.get_singles_dict(self.doctype)
        if (not single_doc):
            single_doc = frappe.new_doc(self.doctype).as_dict()
            single_doc[u'name'] = self.doctype
            del single_doc[u'__islocal']
        super(Document, self).__init__(single_doc)
        self.init_valid_columns()
        self._fix_numeric_types()
    else:
        d = frappe.db.get_value(self.doctype, self.name, u'*', as_dict=1)
        if (not d):
            frappe.throw(_(u'{0}    {1}    not    found').format(_(self.doctype), self.name), frappe.DoesNotExistError)
        super(Document, self).__init__(d)
    if ((self.name == u'DocType') and (self.doctype == u'DocType')):
        from frappe.model.meta import doctype_table_fields
        table_fields = doctype_table_fields
    else:
        table_fields = self.meta.get_table_fields()
    for df in table_fields:
        children = frappe.db.get_values(df.options, {u'parent': self.name, u'parenttype': self.doctype, u'parentfield': df.fieldname}, u'*', as_dict=True, order_by=u'idx    asc')
        if children:
            self.set(df.fieldname, children)
        else:
            self.set(df.fieldname, [])
    if hasattr(self, u'__setup__'):
        self.__setup__()
