This is a follow up on my previous question.
I set up the models with ReferenceProperty:
class User(db.Model):
userEmail = db.StringProperty()
class Comment(db.Model):
user = db.ReferenceProperty(User, collection_name="comments")
comment = db.StringProperty(multiline=True)
class Venue(db.Model):
user = db.ReferenceProperty(User, collection_name="venues")
venue = db.StringProperty()
In datastore I have this entry under User:
Entity Kind: User
Entity Key: ag1oZWxsby0xLXdvcmxkcgoLEgRVc2VyGBUM
ID: 21
userEmail: az@example.com
And under Venue:
Entity Kind: Venue
Entity Key: ag1oZWxsby0xLXdvcmxkcgsLEgVWZW51ZRhVDA
ID: 85
venue (string): 5 star venue
user (Key): ag1oZWxsby0xLXdvcmxkcgoLEgRVc2VyGBUM
User: id=21
I am trying to display the item in hw.py
like this
query = User.all()
results = query.fetch(10)
self.response.out.write("<html><body><ol>")
for result in results:
self.response.out.write("<li>")
self.response.out.write(result.userEmail)
self.response.out.write(result.venues)
self.response.out.write("</li>")
self.response.out.write("</ol></body></html>")
This line works:
self.response.out.write(result.userEmail)
But this line does not work:
self.response.out.write(result.venues)
But as per vonPetrushev's answer result.venues
should grab the venue
associated with this userEmail
.
Sorry if this is confusing: I am just trying to access the tables linked to the userEmail
with ReferenceProperty
. The linked tables are Venue
and Comment
. How do I access an item in Venue
or in Comment
? Thanks.