GAE datastore - count records between one minute ago and two minutes ago?

Posted by Arthur Wulf White on Stack Overflow See other posts from Stack Overflow or by Arthur Wulf White
Published on 2012-04-14T17:11:46Z Indexed on 2012/04/15 5:29 UTC
Read the original article Hit count: 211

I am using GAE datastore with python and I want to count and display the number of records between two recent dates. for examples, how many records exist with a time signature between two minutes ago and three minutes ago in the datastore. Thank you.

#!/usr/bin/env python

import wsgiref.handlers
from google.appengine.ext import db
from google.appengine.ext import webapp
from google.appengine.ext.webapp import template
from datetime import datetime

class Voice(db.Model):
    when = db.DateTimeProperty(auto_now_add=True)


class MyHandler(webapp.RequestHandler):
    def get(self):
        voices = db.GqlQuery(
            'SELECT * FROM Voice '
            'ORDER BY when DESC')
        values = {
            'voices': voices
        }
        self.response.out.write(template.render('main.html', values))
    def post(self):
        voice = Voice()
        voice.put()
        self.redirect('/')
        self.response.out.write('posted!')  

def main():
    app = webapp.WSGIApplication([
        (r'.*', MyHandler)], debug=True)
    wsgiref.handlers.CGIHandler().run(app)

if __name__ == "__main__":
    main()

© Stack Overflow or respective owner

Related posts about python

Related posts about google-app-engine