class Post(db.DynamicDocument): created_at = db.DateTimeField(default=datetime.datetime.now, required=True) title = db.StringField(max_length=255, required=True) slug = db.StringField(max_length=255, required=True) category = db.StringField(max_length=255, required=True) tags = db.StringField(required=False) comments = db.ListField(db.EmbeddedDocumentField('Comment')) def get_absolute_url(self): return url_for('post', kwargs={"slug": self.slug}) def __unicode__(self): return self.title @property def post_type(self): return self.__class__.__name__ meta = { 'allow_inheritance': True, 'indexes': ['-created_at', 'slug'], 'ordering': ['-created_at'] }
class Comment(db.EmbeddedDocument): created_at = db.DateTimeField(default=datetime.datetime.now, required=True) body = db.StringField(verbose_name="Comment", required=True) author = db.StringField(verbose_name="Name", max_length=255, required=True)
class Quote(Post): body = db.StringField(required=True) author = db.StringField(verbose_name="Author Name", required=True, max_length=255)
class Image(Post): image_url = db.StringField(required=True, max_length=255)
class Video(Post): embed_code = db.StringField(required=True)
class BlogPost(Post): body = db.StringField(required=True)