here is my code : # -*- coding: utf-8 -*- import os import re import random import hashlib import hmac from string import letters
import webapp2 import jinja2 from google.appengine.ext import db template_dir = os.path.join(os.path.dirname(__file__), 'templates') jinja_env = jinja2.Environment(loader = jinja2.FileSystemLoader(template_dir), autoescape = True) class Handler(webapp2.RequestHandler): def write(self, *a, **kw): self.response.out.write(*a, **kw) def render_str(self, template, **params): t = jinja_env.get_template(template) return t.render(params) def render(self, template, **kw): self.write(self.render_str(template, **kw)) class MainPage(Handler): def get(self): self.write('Hello, guys') class Book(db.Model): deal = db.IntegerProperty(required= True) created = db.DateTimeProperty(auto_now_add=True) sum_deal = db.IntegerProperty(required= True) # the code above is class BookMe(Handler): def render_book(self,sum_deal="", deal="",error=""): #sum_deal = 0 deals = db.GqlQuery("SELECT * FROM Book ORDER BY created DESC") # assign the query content to a variable self.render("book.html", sum_deal=sum_deal,deal=deal,error=error,deals=deals) # render the webpage , take care of the parameters def get(self): self.render_book() def post(self): deal = int(self.request.get("deal")) if deal: b = Book(deal=deal,sum_deal=sum_deal) for deal in deals: sum_all += deal.deal b.put() self.redirect("/book") # set a instance of model object then put the data into datastore else: error = "we need both a title and some artwork!" self.render_front(error = error) class Delete_row(Handler): def GET(self,dealid): self.write("i have delete %d"%deal.key().id()) self.redirect('/book') def POST(self): dealid = deal.key().id() todelete = db.get(dealid) if todelete: todelete.delete() app = webapp2.WSGIApplication([('/', MainPage), ('/book', BookMe), (r'/del/([0-9]+)',Delete_row), ],debug=True) I want to show the sum of deal in the front page , and i know that datastore has not that built-in , so i want to iterate all the entities and sum them up to store it in a variable. but it doesnt work. and i also want to implement the delete function to delete some contents. -- You received this message because you are subscribed to the Google Groups "Google App Engine" group. To view this discussion on the web visit https://groups.google.com/d/msg/google-appengine/-/vYSFOenlLZQJ. To post to this group, send email to google-appengine@googlegroups.com. To unsubscribe from this group, send email to google-appengine+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en.