'Returns the highest `idx`'

def get_max_idx(self):

    max_idx = frappe.db.sql(u'select    max(idx)    from    `tabDocField`    where    parent    =    %s', self.name)
    return ((max_idx and max_idx[0][0]) or 0)
