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( ...

Get Mastering Flask now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.