修改或更改 py2neo 中的关系属性
Modify or change relationship properties in py2neo
有没有办法在使用 py2neo 或 cypher 设置关系后更改关系 属性?我正在创建一个库存跟踪器,一旦一个项目是 "CHECKED_OUT",关系中称为 "status" 的 属性 设置为 "True"。理想情况下,一旦物品被退回或登记,我想将 "status" 属性 更改为 "False"。这样我就可以跟踪该项目并防止它被检查两次。
这是我为结账交易创建关系的代码:
def check_out(self, barcode):
emp = self
item = barcode
id = str(uuid.uuid4())
timestamp = int(datetime.now().strftime("%s"))
date = datetime.now().strftime("%F")
status=True
rel = Relationship(emp, "CHECKED_OUT", item, id=id, timestamp=timestamp, date=date, status=status)
if not(graph.create_unique(rel)):
return True
else:
return False
我已经通读了 py2neo API,但似乎找不到答案。如果修改关系是错误的方法,你能提供更好的方法吗?
沿着这条线的东西应该有效:
def check_in(self, barcode):
item = barcode
# get the relationship
for rel in graph.match(start_node=self, rel_type="CHECKED_OUT", end_node=item):
# set property
rel.properties["status"] = False
rel.push()
参见match()
:http://py2neo.org/2.0/essentials.html#py2neo.Graph.match
和properties
:http://py2neo.org/2.0/essentials.html#py2neo.Relationship.properties
非常感谢。然而,它起作用了,它更新了项目和人之间的所有关系。我稍微修改了您的回复以确保我更新了正确的关系。再次谢谢你。我在下面包含了更新版本。
def check_in(self, barcode, id):
item = barcode
#get the relationship
for rel in graph.match(start_node=self, rel_type="CHECKED_OUT", end_node=item):
if rel["id"] == id:
#set property
rel.properties["status"] = False
rel.push()
有没有办法在使用 py2neo 或 cypher 设置关系后更改关系 属性?我正在创建一个库存跟踪器,一旦一个项目是 "CHECKED_OUT",关系中称为 "status" 的 属性 设置为 "True"。理想情况下,一旦物品被退回或登记,我想将 "status" 属性 更改为 "False"。这样我就可以跟踪该项目并防止它被检查两次。
这是我为结账交易创建关系的代码:
def check_out(self, barcode):
emp = self
item = barcode
id = str(uuid.uuid4())
timestamp = int(datetime.now().strftime("%s"))
date = datetime.now().strftime("%F")
status=True
rel = Relationship(emp, "CHECKED_OUT", item, id=id, timestamp=timestamp, date=date, status=status)
if not(graph.create_unique(rel)):
return True
else:
return False
我已经通读了 py2neo API,但似乎找不到答案。如果修改关系是错误的方法,你能提供更好的方法吗?
沿着这条线的东西应该有效:
def check_in(self, barcode):
item = barcode
# get the relationship
for rel in graph.match(start_node=self, rel_type="CHECKED_OUT", end_node=item):
# set property
rel.properties["status"] = False
rel.push()
参见match()
:http://py2neo.org/2.0/essentials.html#py2neo.Graph.match
和properties
:http://py2neo.org/2.0/essentials.html#py2neo.Relationship.properties
非常感谢。然而,它起作用了,它更新了项目和人之间的所有关系。我稍微修改了您的回复以确保我更新了正确的关系。再次谢谢你。我在下面包含了更新版本。
def check_in(self, barcode, id):
item = barcode
#get the relationship
for rel in graph.match(start_node=self, rel_type="CHECKED_OUT", end_node=item):
if rel["id"] == id:
#set property
rel.properties["status"] = False
rel.push()