Skip to content

Instantly share code, notes, and snippets.

@ismaild
Created November 29, 2012 08:35
Show Gist options
  • Select an option

  • Save ismaild/4167608 to your computer and use it in GitHub Desktop.

Select an option

Save ismaild/4167608 to your computer and use it in GitHub Desktop.
mongoengine models
import datetime
from flask import url_for
from dashboard import db
class Page(db.Document):
title = db.StringField(max_length=100, required=True)
slug = db.StringField(max_length=100, required=True)
parent = db.StringField(max_length=100, required=False, default='')
ancestors = db.ListField()
blocks = db.ListField(db.ListField(db.EmbeddedDocumentField('Block')))
def __unicode__(self):
return self.title
meta = {
'allow_inheritance': True,
'ordering': ['-created_at']
}
class Block(db.EmbeddedDocument):
title = db.StringField(max_length=100, required=True)
block_id = db.StringField( required=True)
block_type = db.StringField(default='Chart', required=True)
options = db.EmbeddedDocument(self.block_type + 'Block')
def __unicode__(self):
return self.title
class ChartBlock(Block):
width = db.StringField(max_length=100, required=False)
height = db.StringField(max_length=100, required=False)
chart_type = db.StringField(max_length=100, required=False)
url = db.StringField(max_length=100, required=False)
def __unicode__(self):
return self.url + self.type
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment