How to get the name attribute in my Python API for Google AppEngine?

45 Views Asked by At

I have a model class. It is a User. The user has many different attributes, but for the sake of the question I will only post a few and the one that is the most important.

This is my models.py

from endpoints_proto_datastore.ndb.model import EndpointModel
from google.appengine.ext import ndb

class User(EndpointsModel):
    _message_fields_schema = ("entityKey", "first_name", "age", "user_bucket")
    first_name = ndb.StringProperty()
    age = ndb.IntegerProperty()
    user_bucket = ndb.StringProperty()

in my user_api.py when the user is created, the user is put into the datastore as well give that user a unique bucket name that was created for them. I have successfully written the code that will create the bucket for them and stores the string in the User model.

What I want to know is how, in my user_api.py file, what method do I use that will return the string of the user_bucket of the User that I specified.

Here is an example of the api. Without the all the annotations and imports.

class UserApi(protorpc.remote.Service):
    pass

    def user_create(self, request):
        if request.from_datastore:
            my_user= request
        else:
            my_user = User(parent=main.USER_PARENT_KEY, first_name=request.first_name, age=request.age)


        """Then I create a unique string name for the bucket name with a time stamp"""
        my_user.user_bucket = USER_BUCKET
        my_user.put()

What I want to know is what api method do I write and how do I write it to return the bucket of the user that I input to the method and do I use the entity key? I am completely lost on this one.

0

There are 0 best solutions below