Is there a way to return datastore entity by making it part of request/response message in cloud endpoint api implementation in python?
For example:
I have entity model defined as below
class District(ndb.Model):
code = ndb.StringProperty(required=True)
Now I want to implement cloud api in python as
@endpoints.method(request_message=DistrictMessage, response_message=DistrictMessage, name="DistrictApi.get_by_code")
def get_by_code(self, request):
#get code from District object in request message and
#try to get entity based on it from datastore
where DistrictMessage is defined as
class DistrictMessage(messages.Message):
district = messages.MessageField(District, 1, required=False)
Above doesn't work as District is not a messages.Message but ndb.Model. We can do similar thing in GAE Java but I am not able to find it for python. Is it even possible? Or do I have to define a Message class for each Entity and do to/from mapping?
Thank you, rizTaak