O'Reilly logo

Mastering Flask by Jack Stouffer

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required