Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Mastering Google App Engine

You're reading from   Mastering Google App Engine Build robust and highly scalable web applications with Google App Engine

Arrow left icon
Product type Paperback
Published in Oct 2015
Publisher
ISBN-13 9781784396671
Length 368 pages
Edition 1st Edition
Languages
Arrow right icon
Toc

Querying your data


Before we can query some data, we should have some data. So, our first step will be to generate some sample data on which we can experiment with the query API that is provided by datastore. We will take our old Listing model from the previous chapters and add a few more fields to it. Next, we will create some listings for cars from 1990 to 2000 that come with a random price assigned to each.

So, the following is the program that does this:

from google.appengine.ext import ndb 
import random 

class Listing(ndb.Model): 
    title = ndb.StringProperty() 
    year = ndb.IntegerProperty() 
    price = ndb.IntegerProperty(default=0) 

for year in xrange(1990, 2001): 
    car = Listing() 
    car.title = "Honda Civic %s" % year 
    car.price = random.randint(4000, 50000) 
    car.year = year 
    car.put() 

So, as you can see, we have a Listing model with title, year, and price. We created a Listing instance, assigned a title to it, set a random price, and the year was assigned...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime