I am developing a blog project using jinja2 for templates, Google App Engine for hosting and running it and Python as the server side language.
So, my models.py looks like this :
from google.appengine.ext import ndb
class User(ndb.Model):
fullname = ndb.StringProperty(required=True)
user_name = ndb.StringProperty(required=True)
email = ndb.StringProperty(required=True)
password = ndb.TextProperty(indexed=True,required=True)
photo = ndb.StringProperty()
location = ndb.StringProperty()
class Post(ndb.Model):
title = ndb.StringProperty(required=True)
content = ndb.TextProperty(required=True)
created = ndb.DateTimeProperty(auto_now_add=True)
last_modified = ndb.DateTimeProperty(auto_now=True)
user = ndb.KeyProperty(kind=User)
Now what I want is to have a result set like this :
User.fullname | User.Photo | Post.*
I am showing the above details for a single post. Now each Post entry is linked with a User with the User's Key.
Now since joins are not supported in ndb query class, how do I fetch and merge the two results ?
I tried the GQL like this :
select User.fullname, User.photo, User.id, Post.title, Post.content, Post.created
from User, Post
where User.__key__ == Post.user
But I get this error when I run this in the GQLQuery in my datastore console :
GQL query error: Encountered "," at line 2, column 10. Was expecting one of: "group", "limit", "offset", "order", "where"
Any suggestions ?
TIA
EDIT:1 Tried this query :
posts = ndb.query(User,Post).filter(User.key == Post.user).order(-Post.created)
But I get the following error:
TypeError: 'module' object is not callable
EDIT:2 Here is an index I tried :
kind: Post
properties:
- name: content
- name: created
- name: user
direction: desc
But doesn't seem to work :O
posts = ndb.query(User,Post).filter(User.key == Post.user).order(-Post.created)but unfortunately I get this error :TypeError: 'module' object is not callable- Abhishek Ghosh