Commit 572f1d39 authored by Paul Brown's avatar Paul Brown

Merge pull request #1156 from mikelambert/master

Add a demo app for appengine (and fix one more bug)
parents 1595568e 9fba3f89
......@@ -19,6 +19,7 @@ __pycache__
examples/sqla-inline/static
examples/file/files
examples/forms/files
examples/appengine/lib
.DS_Store
.idea/
*.sqlite
......
from flask import Flask
import flask_admin
from flask_admin.contrib import appengine
from google.appengine.ext import db
from google.appengine.ext import ndb
# Create application
app = Flask(__name__)
# Create dummy secrey key so we can use sessions
app.config['SECRET_KEY'] = '123456790'
admin = flask_admin.Admin(app, name="Admin")
# Flask views
@app.route('/')
def index():
return '<a href="/admin/">Click me to get to Admin!</a>'
class Car(db.Model):
owner = db.StringProperty()
make_model = db.StringProperty()
indexed_int = db.IntegerProperty()
unindexed_int = db.IntegerProperty(indexed=False)
class Tire(db.Model):
car = db.ReferenceProperty(Car)
position = db.StringProperty()
class House(ndb.Model):
address = db.StringProperty()
json_property = ndb.JsonProperty()
indexed_int = ndb.IntegerProperty()
unindexed_int = ndb.IntegerProperty(indexed=False)
text_property = ndb.TextProperty()
datetime_property = ndb.DateTimeProperty()
class Room(ndb.Model):
house = ndb.KeyProperty(kind=House)
name = ndb.StringProperty()
admin.add_view(appengine.ModelView(Car))
admin.add_view(appengine.ModelView(Tire))
admin.add_view(appengine.ModelView(House))
admin.add_view(appengine.ModelView(Room))
if __name__ == '__main__':
# Start app
app.run(debug=True)
runtime: python27
threadsafe: true
api_version: 1
module: default
handlers:
- url: /admin.*
script: app.app
# This file gets imported as part of running dev_appserver.py
import sys
sys.path = ['lib'] + sys.path
BASEDIR=$(dirname $0)
# Install wtforms-admin to our lib/ directory, using our local source tree
pip install -t $BASEDIR/lib/ $BASEDIR/../.. wtforms_appengine
# Now run our server
dev_appserver.py $BASEDIR/app.yaml
......@@ -101,7 +101,8 @@ class DbModelView(BaseModelView):
return sorted([k for (k, v) in self.model.__dict__.iteritems() if isinstance(v, db.Property)])
def scaffold_sortable_columns(self):
return [k for (k, v) in self.model.__dict__.iteritems() if isinstance(v, db.Property) and v.indexed]
# We use getattr() because ReferenceProperty does not specify a 'indexed' field
return [k for (k, v) in self.model.__dict__.iteritems() if isinstance(v, db.Property) and getattr(v, 'indexed', None)]
def init_search(self):
return None
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment