Google App Engine - Python appication: find relationship among nodes
I have following model:
class Relations(db.Model):
name = db.StringProperty()
events = db.StringListProperty(required = True)
and following Relations data:
name = direct events = [node_A,event_B],
name = inverse events = [node_A,node_G],
name = direct events = [node_A,node_H],
name = inverse events = [node_A,node_X],
name = direct events = [node_A,node_Y]
and based on user input (e.g node_A up) I need开发者_如何学Python to find the relationship among nodes and output the nodes as follows:
output: node_B - up, node_G - down, node_H - up, node_X - down, node_Y - up
In other words I need queries to find out relationship among nodes for example, if relationship of node_A to node_B is direct and node_A to node_X is inverse output will be node_B - up and node_X - down as in the output example above.
If user input will be node_G down then output required is node_A down since there are no other nodes related to node_G except node_A.
Please suggest the queries. Thanks in advance Prakash
If I understand correctly, something like this could work:
query = Relations.all()
query.filter('events =', node)
direct_list = []
inverse_list = []
for relation in query:
relation.events.remove(node)
if relation.name == 'direct':
direct_list.extend(relation.events)
else:
inverse_list.extend(relation.events)
if action == 'up':
#direct_list is all 'up'
#inverse_list is all 'down'
else:
#opposite of above
精彩评论