def getDepartment(dep): if not dep: return None d = Department.nodes.get_or_none(name=dep) if not d: d = Department(name=dep).save() return d