google-app-engine


Many-to-many relationship modeling in google app engine


I followed what is outlined here. Here is my code:
from google.appengine.api import users
from google.appengine.ext import db
class Book(db.Model):
title = db.StringProperty()
class Author(db.Model):
name = db.StringProperty()
class BookAuthor(db.Model):
book = db.ReferenceProperty(Book, required=True, collection_name='books')
author = db.ReferenceProperty(Author, required=True, collection_name='authors')
b = Book(title="My Book")
a = Author(name="Author of My Book")
db.put([b, a])
ba = BookAuthor(book=b, author=a)
ba.put()
b.authors
a.books
and I get AttributeError: 'Book' object has no attribute 'authors'
ReferenceProperties add query-objects as attributes to the referenced class. So look carefully at your mappings:
class BookAuthor(db.Model):
# This adds a query-object as an attribute named 'books' to Book entities.
book = db.ReferenceProperty(Book, required=True, collection_name='books')
# This adds a query-object as an attribute named 'authors' to Author entities.
author = db.ReferenceProperty(Author, required=True, collection_name='authors')
In your code:
b = Book(title="My Book")
a = Author(name="Author of My Book")
So, b would have a books attribute, not authors. And, a would have a authors attribute, not books.
If you change the collection names, your code should run.
class BookAuthor(db.Model):
# This adds a query-object as an attribute named 'authors' to Book entities.
book = db.ReferenceProperty(Book, required=True, collection_name='authors')
# This adds a query-object as an attribute named 'books' to Author entities.
author = db.ReferenceProperty(Author, required=True, collection_name='books')
Also, if BookAuthor does not have additional properties, make sure you look at the list-of-keys method outlined in the article you referenced.

Related Links

Importing data into 2nd generation google cloud sql
App Engine: What is the Maximum URLFetch Timeout Deadline in a Taskqueue / Backend
Using URL-safe keys in Google Cloud Datastore
AttributeError on google cloud datastore entity object
Is there any way to handle Google Datastore Kind Property names with spaces in Golang?
Google App Engine: Disable favicon.ico
Google Cloud DataStore. How to serve data?
How to access a cloud storage bucket from app engine without getting the 403 FORBIDDEN error?
Google App Engine Custom Domain - Routing in Go
Best approach for caching lists of objects in memcache
com.google.gcloud.datastore vs com.google.appengine.api.datastore
Google App Engine - Issue with creating a bulkloading config
Solr Timeout error even data is instered
Why does BigQuery fail to parse an Avro file that is accepted by avro-tools?
Insufficient Permission with Appengine Flex service account to access Drive folder
Getting Invalid Key message thrown when creating child records

Categories

HOME
xml
azure-stream-analytics
design-patterns
apache-jena
pagination
rsa
mstest
socket.io
requirements
devise
nsbundle
cq5
ado.net
vert.x
okhttp
ibeacon-android
activecollab
filechannel
libc
automatic-ref-counting
symmetricds
magnetic-cards
flatpak
heat
mongodb-csharp
feathersjs
google-data-studio
google-container-registry
charles
tosca
zxing
froala
rpgle
winexe
postback
mustache
record
angularjs-material
wacom
instantiation
installshield-le
fossil
carriage-return
slacktextviewcontroller
browser-extension
graphhopper
metawidget
magento-1.9.3
escpos
congestion-control
user-defined-fields
zenhub
reindex
custom-font
spring-data-couchbase
git-flow
quicktime
bbpress
rackspace-cloud
django-1.10
mapxtreme
autosar
nikeplus-api
dimension
google-query-language
libav
blitline
jaunt-api
character-replacement
android-launcher
linked-tables
dnssec
snackbar
mraid
osc
ejb-2.x
cosine-similarity
execve
webmatrix-3
paw
mdichild
extjs2
rfc5322
light
ie8-compatibility-mode
code-duplication
away3d
mysql-error-2013
sqlclr
curb
correlated-subquery
objectquery
kqueue
jquery-address
google-maps-mobile
dataform
unattended-processing
uideviceorientation
fault-tolerance
httpcookie
contentpresenter

Resources

Encrypt Message