I have the following models and respective methods on my project:
class Users(ndb.Expando):
"""
flefu users, identified by email.
user_gender --> 0 = male; 1 = female; 2 = other; 3 = unknown
"""
join_date = ndb.DateTimeProperty(auto_now_add=True)
user_name = ndb.StringProperty(required=True)
user_email = ndb.StringProperty(required=True)
class UsersPhotos(ndb.Model):
"""
property to processes a blob upload steps
Users child.
"""
upload_date = ndb.DateTimeProperty(auto_now_add=True)
photo_key = ndb.BlobKeyProperty(required=True)
photo_serving_url = ndb.StringProperty(required=True)
@classmethod
def insert_from_form(cls, data):
user_key = ndb.Key(Users, data.userId)
photo_details = cls(
parent=user_key,
user=user_key,
photo_key=data.photoKey,
photo_serving_url=data.photoServingUrl
)
photo_details.put()
photo_details.status = "200"
photo_details.parent = user_key.id()
return photo_details
@classmethod
def get_photos_by_users(cls, data):
users = Users.query().fetch(20)
for user in users:
logging.info(str(user.key))
photo_data = cls.query(ancestor=user.key).fetch()
logging.info(str(photo_data))
photos = cls.query().fetch(10)
logging.info(str(photos))
I'm not sure why the photo_data query always return an empty list. The empty list is returned on both the Dev app engine service(local) and the hosted app engine service (remote).
The Users and UsersPhotos kinds have the following entities:
Users:
Users(key=Key('Users', 5629499534213120), join_date=datetime.datetime(2014, 7, 26, 4, 40, 11, 840853), user_email=u'[email protected]', user_name=u'hidden')
UsersPhotos:
[
UsersPhotos(key=Key('Users', '5629499534213120', 'UsersPhotos', 6192449487634432), photo_key=datastore_types.BlobKey('encoded_gs_file:YXBwX2RlZmF1bHRfYnVja2V0L2Zha2UtdzZSYkpZS1RnTlpkY3JKRVI3dUU2UT09'), photo_serving_url=u'http://127.0.0.1:8080/_ah/img/encoded_gs_file:YXBwX2RlZmF1bHRfYnVja2V0L2Zha2UtdzZSYkpZS1RnTlpkY3JKRVI3dUU2UT09=s300', upload_date=datetime.datetime(2014, 7, 26, 4, 40, 35, 455648)),
UsersPhotos(key=Key('Users', '5629499534213120', 'UsersPhotos', 6473924464345088), photo_key=datastore_types.BlobKey('encoded_gs_file:YXBwX2RlZmF1bHRfYnVja2V0L2Zha2UtcmZiYU5WNEFSVnZheG81aGQ5dXpNdz09'), photo_serving_url=u'http://127.0.0.1:8080/_ah/img/encoded_gs_file:YXBwX2RlZmF1bHRfYnVja2V0L2Zha2UtcmZiYU5WNEFSVnZheG81aGQ5dXpNdz09=s300', upload_date=datetime.datetime(2014, 7, 26, 4, 41, 12, 322560))
]
Can someone point me on the right direction?