def add_post(): form = PostForm(request.form) if form.validate_on_submit(): status = PostStatus.from_string(form.status.data) post = Post(author=current_user, title=form.title.data, slug=form.slug.data, body=form.body.data, status=status, tags=form.tags.data) if status == PostStatus.published: post.pub_date = utc_now() db.session.add(post) db.session.commit() message = u'Post "{}" successfully added.'.format(form.title.data) flash(message, 'success') return redirect(url_for('.view_posts')) return render_template('blog/post_add.html', form=form)
def populate_obj(self, obj, name): setattr(obj, name, PostStatus.from_string(self.data))