Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion appengine/standard/ndb/schema_update/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
populate these new fields onto entities that existed prior to adding the
new fields to the model class.
"""

# [START imports]
import logging
import os

Expand All @@ -38,8 +38,10 @@
os.path.join(os.path.dirname(__file__), 'templates')),
extensions=['jinja2.ext.autoescape'],
autoescape=True)
# [END imports]


# [START display_entities]
class DisplayEntitiesHandler(webapp2.RequestHandler):
"""Displays the current set of entities and options to add entities
or update the schema."""
Expand All @@ -54,8 +56,10 @@ def get(self):

template = JINJA_ENVIRONMENT.get_template('index.html')
self.response.write(template.render(template_values))
# [END display_entities]


# [START add_entities]
class AddEntitiesHandler(webapp2.RequestHandler):
"""Adds new entities using the v1 schema."""
def post(self):
Expand All @@ -71,8 +75,10 @@ def post(self):
self.response.write("""
Entities created. <a href="/">View entities</a>.
""")
# [END add_entities]


# [START update_schema]
class UpdateSchemaHandler(webapp2.RequestHandler):
"""Queues a task to start updating the model schema."""
def post(self):
Expand Down Expand Up @@ -123,6 +129,7 @@ def update_schema_task(cursor=None, num_updated=0, batch_size=100):
logging.debug(
'update_schema_task complete with {0} updates!'.format(
num_updated))
# [END update_schema]


app = webapp2.WSGIApplication([
Expand Down
2 changes: 2 additions & 0 deletions appengine/standard/ndb/schema_update/models_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
from google.appengine.ext import ndb


# [START models_v1]
class Picture(ndb.Model):
author = ndb.StringProperty()
name = ndb.StringProperty(default='')
# [END models_v1]
2 changes: 2 additions & 0 deletions appengine/standard/ndb/schema_update/models_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
from google.appengine.ext import ndb


# [START models_v2]
class Picture(ndb.Model):
author = ndb.StringProperty()
name = ndb.StringProperty(default='')
# Two new fields
num_votes = ndb.IntegerProperty(default=0)
avg_rating = ndb.FloatProperty(default=0)
# [END models_v2]