在我的models.py文件中,我有:
class Place(models.NodeModel):
name = models.StringProperty()
class Person(models.NodeModel):
name = models.StringProperty()
age = models.IntegerProperty()
location = models.Relationship('self', rel_type='lives_in', related_name='place')
class Pet(models.NodeModel):
name = models.StringProperty()
owner = models.Relationship(Person,
rel_type='owns',
single=True,
related_name='pets'
)
然后我有一个实例' Pete'类Person:
neo4j-sh (Pete,2)$ ls
==> *age =[30]
==> *name =[Pete]
==> (me)-[:owns]->(Garfield,4)
==> (me)-[:lives_in]->(London,6)
==> (me)<-[:<<INSTANCE>>]-(mydb:Person,1)
我没有问题获得Pete的年龄和名字,但我在查询相关实体方面遇到了麻烦。
例如,试图获取他的位置,我运行
Person.objects.get(name='Pete').select_related('place')[0].name
但是我收到了一个错误:AttributeError:&#39; Person&#39;对象没有属性&#39; select_related&#39;
你能告诉我我做错了什么吗?