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...