5

So I've trying to model a small user-group relationship in Neo4j with Django. I am currently employing the Neo4django python package seen here. Now, I have nodes representing my users, and nodes representing my groups, and relationships that link them indicating membership. What I'm hoping to also do in the near future is add properties to this relationship such as date_joined. I looked around but there isn't too much documentation on how to achieve this. I'm sure there is a way of doing it, just haven't seen any examples around.

Below is the declaration for my model.py if necessary, I think it's pretty straight forward.

class User(models.NodeModel):
    friends = models.Relationship('User', rel_type=Outgoing.FRIEND, related_single=False, related_name='friends')
    groups = models.Relationship('Group', rel_type=Outgoing.USER_GROUPS, related_single=False, related_name='groups')
    user_name = models.StringProperty(max_length=30, indexed=True)
    password = models.StringProperty(max_length=128)

class Group(models.NodeModel):
    users = models.Relationship('User', rel_type=Outgoing.MEMBER, related_single=False, related_name='members')
    group_type = models.Relationship('GroupType', rel_type=Outgoing.GROUP_TYPE, related_single=True, related_name='group_type')
    group_name = models.StringProperty(max_length=128, indexed=True)
    date_creation = models.DateProperty()

Thanks for any pointers!

4

1 回答 1

4

According to the people maintaining Neo4django, there is work in progress to allow user to inherit from neo4django.db.model.Relationship in order to add properties similar to Models. This has yet to be implemented. The workaround in the meantime is to use a node in between two nodes to store properties about the relationship.

于 2012-10-27T19:05:37.780 回答