2
我從Neo4j的數據庫和Django的neomodel, 使用我希望實現以下系統爲我的用戶,寫這種模式爲用戶:Django的一個下列型號neomodel
class UserNode(StructuredNode):
user_id = IntegerProperty(required=True, index=True)
follow = RelationshipTo('UserNode','FOLLOW')
def get_followers(self):
results, metadata = self.cypher("START a=node({self}) MATCH a<-[:FOLLOW]-(b) RETURN b");
return [self.__class__.inflate(row[0]) for row in results]
def get_following(self):
results, metadata = self.cypher("START a=node({self}) MATCH b-[:FOLLOW]->(a) RETURN b");
return [self.__class__.inflate(row[0]) for row in results]
def follow_person(self, user_id):
import datetime
from django.utils.timezone import utc
followed_user = self.index.get(user_id=user_id)
self.follow.connect(followed_user, {'time': str(datetime.datetime.utcnow().replace(tzinfo=utc))})
self.save()
followed_user.save()
你覺得我UserNode模型以下系統是一個很好的模型?
和這個模型的問題occoured! 當我運行這段代碼:
a = UserNode.index.get(user_id=200)
b = UserNode.index.get(user_id=201)
c = UserNode.index.get(user_id=202)
a.follow_person(201)
b.follow_person(200)
print a.get_followers(), a.get_following()
輸出兩名空列表。爲什麼?