def get_max_idx(self):
		max_idx = frappe.db.sql("""select max(idx) from `tabDocField` where parent = %s""",
			self.name)
		return max_idx and max_idx[0][0] or 0
Returns the highest `idx`
dataset/ETHPy150Open frappe/frappe/frappe/core/doctype/doctype/doctype.py/DocType.get_max_idx