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()) meta = { 'allow_inheritance': True }
Each post type...