Skip to content

Instantly share code, notes, and snippets.

@yanmhlv
Created July 19, 2013 20:06
Show Gist options
  • Save yanmhlv/6041988 to your computer and use it in GitHub Desktop.
Save yanmhlv/6041988 to your computer and use it in GitHub Desktop.
simple mongoengine model connect to mongohq.com
# coding: utf-8
from flask import Flask, request, jsonify
import mongoengine as me
class User(me.Document):
email = me.EmailField(required = True)
register_at = me.DateTimeField(required = True)
activation = me.BooleanField()
meta = {'collection': 'user'}
# Flask-Login integration
def is_authenticated(self):
return True
def is_active(self):
return True
def is_anonymous(self):
return False
def get_id(self):
#return self._id
return self.id
# Required for administrative interface
def __unicode__(self):
return '<User: %s %s>' % (self.id, self.email)
@classmethod
def email_exists(cls, email):
return cls.objects(email = email).first()
#app = Flask(__name__)
if __name__ == '__main__':
import datetime
me.connect('DBNAME', host = 'dharma.mongohq.com', username = 'username', password = 'password', port = PORT)
#app.run(debug = True)
#print User.objects.first()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment