Skip to content

Instantly share code, notes, and snippets.

@johnschimmel
Created October 9, 2012 14:28
Show Gist options
  • Save johnschimmel/3859174 to your computer and use it in GitHub Desktop.
Save johnschimmel/3859174 to your computer and use it in GitHub Desktop.
example model with mongoengine and wtforms
# -*- coding: utf-8 -*-
from mongoengine import *
from flask.ext.mongoengine.wtf import model_form
from datetime import datetime
class Comment(EmbeddedDocument):
name = StringField()
comment = StringField()
timestamp = DateTimeField(default=datetime.now())
class Idea(Document):
creator = StringField(max_length=120, required=True, verbose_name="First name")
title = StringField(max_length=120, required=True)
slug = StringField()
idea = StringField(required=True, verbose_name="What is your idea?")
# Category is a list of Strings
categories = ListField(StringField(max_length=30))
# Comments is a list of Document type 'Comments' defined above
comments = ListField( EmbeddedDocumentField(Comment) )
# Timestamp will record the date and time idea was created.
timestamp = DateTimeField(default=datetime.now())
# Create a Validation Form from the Idea model
IdeaForm = model_form(Idea)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment