Skip to Content
Mastering Flask Web Development - Second Edition
book

Mastering Flask Web Development - Second Edition

by Daniel Gaspar, Jack Stouffer
October 2018
Intermediate to advanced
332 pages
8h 9m
English
Packt Publishing
Content preview from Mastering Flask Web Development - Second Edition

Leveraging the power of NoSQL

To show the unique power of NoSQL, let's add a feature that would be possible with SQLAlchemy, but which would be much more difficult: different post types, each with their own custom bodies. This will be much like the functionality of the popular blog platform Tumblr.

To begin, allow your post type to act as a parent class and remove the text field from the Post class, as not all posts will have text on them. This is shown in the following code:

class Post(mongo.Document): title = mongo.StringField(required=True) publish_date = mongo.DateTimeField(default=datetime.datetime.now()) user = mongo.ReferenceField(Userm) comments = mongo.ListField( mongo.EmbeddedDocumentField(Commentm) ) tags = mongo.ListField(mongo.StringField()) ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Flask Web Development, 2nd Edition

Flask Web Development, 2nd Edition

Miguel Grinberg
Flask Web Development

Flask Web Development

Miguel Grinberg

Publisher Resources

ISBN: 9781788995405Supplemental Content