1

我有一个模型课。它是一个用户。用户有许多不同的属性,但为了这个问题,我只会发布一些最重要的属性。

这是我的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()

在我的 user_api.py 中,当创建用户时,将用户放入数据存储区,并为该用户提供为他们创建的唯一存储桶名称。我已经成功编写了将为他们创建存储桶并将字符串存储在用户模型中的代码。

我想知道的是,在我的 user_api.py 文件中,我使用什么方法将返回我指定的用户的 user_bucket 的字符串。

这是一个api的例子。没有所有的注释和导入。

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()

我想知道的是我写了什么api方法,我如何写它来返回我输入到该方法的用户的桶,我是否使用实体键?我完全迷失了这个。

4

0 回答 0