Leveraging the power of NoSQL
So far, our MongoEngine code should look like the following:
available_roles = ('admin', 'poster', 'default') class User(mongo.Document): username = mongo.StringField(required=True) password = mongo.StringField(required=True) roles = mongo.ListField( mongo.StringField(choices=available_roles) ) def __repr__(self): return '<User {}>'.format(self.username) class Comment(mongo.EmbeddedDocument): name = mongo.StringField(required=True) text = mongo.StringField(required=True) date = mongo.DateTimeField( default=datetime.datetime.now() ) def __repr__(self): return "<Comment '{}'>".format(self.text[:15]) class Post(mongo.Document): title = mongo.StringField(required=True) text = mongo.StringField() publish_date = mongo.DateTimeField( default=datetime.datetime.now() ) user = mongo.ReferenceField(User) comments = mongo.ListField( mongo.EmbeddedDocumentField...