FlockDB provides a very good way to model social graphics: the system has only two objects: “User and friendship”. where the user represents the vertices of the graph, and friendship represents the edges between two users. Like this:
User (id, first_name, last_name, birth_data, registration_timestamp)
Friendship (id, user1_id, user2_id, depth, other parameters of friendship ...)
There are a number of advantages to this approach.
- You can specify options for friendship, such as a friend, close friend, in a relationship
- You can choose whether your friendship is directional or not.
My question is: how to implement this using the DataStore provided by Google AppEngine. here is my first attempt, but I don’t understand how to really assign keys to friendship objects.
class User(db.Model): name = db.StringProperty() age = db.IntegerProperty() registeration_ts = db.DateTimeProperty(auto_now_add=True) class FriendShip(db.Model): user1 = db.Key() // key to some user in user1 user2 = db.Key() // key to some user in user2 creation_ts = db.DateTimeProperty(auto_now_add=True) updated_ts = db.DateTimeProperty(auto_now_add=True)
source share