From 1ab5757e006fcc777d5162c432a9b94330b96036 Mon Sep 17 00:00:00 2001 From: Bruno Rocha Date: Sun, 14 Jul 2013 03:40:09 +0000 Subject: [PATCH] Comments are Embedded again, found the problem SyrusAkbary/Flask-SuperAdmin#77 --- quokka/core/models.py | 23 ++++++++++------------- quokka/modules/posts/views.py | 1 - 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/quokka/core/models.py b/quokka/core/models.py index 48c10f519..6ad470edb 100644 --- a/quokka/core/models.py +++ b/quokka/core/models.py @@ -17,9 +17,17 @@ class Publishable(object): class Slugged(object): slug = db.StringField(max_length=255, required=True) - + +class Comment(db.EmbeddedDocument, Publishable): + body = db.StringField(verbose_name="Comment", required=True) + author = db.StringField(verbose_name="Name", max_length=255, required=True) + published = db.BooleanField(default=True) + + def __unicode__(self): + return "{}-{}...".format(self.author, self.body[:10]) + class Commentable(object): - comments = db.ListField(db.ReferenceField('Comment')) + comments = db.ListField(db.EmbeddedDocumentField(Comment)) class Imaged(object): """TODO: IMplement ImageField""" @@ -75,15 +83,4 @@ def post_type(self): 'ordering': ['-created_at'] } - -class Comment(db.Document, Publishable): - body = db.StringField(verbose_name="Comment", required=True) - author = db.StringField(verbose_name="Name", max_length=255, required=True) - published = db.BooleanField(default=True) - - def __unicode__(self): - return "{}-{}...".format(self.author, self.body[:10]) - - -admin.register(Comment, category="content") admin.register(Channel) diff --git a/quokka/modules/posts/views.py b/quokka/modules/posts/views.py index 09f773288..fe7f8358e 100644 --- a/quokka/modules/posts/views.py +++ b/quokka/modules/posts/views.py @@ -44,7 +44,6 @@ def post(self, slug): if form.validate(): comment = Comment() form.populate_obj(comment) - comment.save(validate=False) post = context.get('post') post.comments.append(comment)