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

Modeling your data

Now let's model something that will explain how keys work. We have a Kind named Listing, which will be used to create listings. However, there is no way for us to put various listings in different categories as yet. How do we do that? There are two approaches.

The first approach – storing a reference as a property

The first approach is pretty simple and is known to us from the RDBMS world. We can create categories separately, and each category will have a reference in each listing. It is similar to how foreign keys work in databases. So, we will have a new property for the Listing entities, which will contain a reference to the category to which it belongs. The category attribute will actually contain the key of an entity of the Category Kind. Let's take a look at the code to better understand it:

from google.appengine.ext import ndb

# Represents a category
class Category(ndb.Model):
  name = ndb.StringProperty()

# Our simple listing model
class Listing...
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