2014-03-25 2 views
-2

나는이 방법으로 두 개의 클래스가 있습니다는 ndb.model합니다 : 구글 앱 egnine

class comment(ndb.Model): 
    date =ndb.StringProperty() 
    title=ndb.StringProperty() 
    name=ndb.StringProperty() 
    content=ndb.StringProperty() 

class report(ndb.Model): 
    comments=ndb.StructuredProperty(comment,repeated=True) 

그래서 난 사용자로부터 코멘트를 얻을 후 보고서 클래스의 목록 주석에 추가,이 내가 무엇을 :

class add(webapp2.RequestHandler): 
    def post(self): 
    key_url=self.request.get("key") 
    key=ndb.Key(urlsafe=key_url) 
    report=key.get() 
    title=self.request.get("title") 
    name=self.request.get("name") 
    date=self.request.get("date") 
    content=self.request.get("content") 
    new_comment=comment(date=date,title=title,name=name,content=content) 
    report.comments.append(new_comment) 
    report.put() 

불행하게도 이것은 내가이 오류가 작동하지 않습니다

BadValueError: Expected string, got comment(key=Key('comment', 5659645909663744), content=u'dasdsad', date=u'', name=u'', title=u'') 

저를 도와주세요! 마지막 코멘트에서 확인

 Traceback (most recent call last): 
    File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1535, in __call__ 
    rv = self.handle_exception(request, response, e) 
    File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1529, in __call__ 
    rv = self.router.dispatch(request, response) 
    File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1278, in default_dispatcher 
    return route.handler_adapter(request, response) 
    File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1102, in __call__ 
    return handler.dispatch() 
    File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 572, in dispatch 
    return self.handle_exception(e, self.app.debug) 
    File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 570, in dispatch 
    return method(*args, **kwargs) 
    File "/base/data/home/apps/s~newseltira/1.374670644492631009/upload_comment.py", line 65, in post 
    report.put() 
    File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/ext/ndb/model.py", line 3339, in _put 
    return self._put_async(**ctx_options).get_result() 
    File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/ext/ndb/tasklets.py", line 325, in get_result 
    self.check_success() 
    File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/ext/ndb/tasklets.py", line 368, in _help_tasklet_along 
    value = gen.throw(exc.__class__, exc, tb) 
    File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/ext/ndb/context.py", line 748, in put 
    key = yield self._put_batcher.add(entity, options) 
    File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/ext/ndb/tasklets.py", line 371, in _help_tasklet_along 
    value = gen.send(val) 
    File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/ext/ndb/context.py", line 280, in _put_tasklet 
    keys = yield self._conn.async_put(options, datastore_entities) 
    File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/datastore/datastore_rpc.py", line 1791, in async_put 
    pbs = [entity_to_pb(entity) for entity in entities] 
    File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/ext/ndb/model.py", line 648, in entity_to_pb 
    pb = ent._to_pb() 
    File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/ext/ndb/model.py", line 3052, in _to_pb 
    prop._serialize(self, pb, projection=self._projection) 
    File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/ext/ndb/model.py", line 1365, in _serialize 
    values = self._get_base_value_unwrapped_as_list(entity) 
    File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/ext/ndb/model.py", line 1135, in _get_base_value_unwrapped_as_list 
    wrapped = self._get_base_value(entity) 
    File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/ext/ndb/model.py", line 1123, in _get_base_value 
    return self._apply_to_values(entity, self._opt_call_to_base_type) 
    File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/ext/ndb/model.py", line 1295, in _apply_to_values 
    value[:] = map(function, value) 
    File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/ext/ndb/model.py", line 1177, in _opt_call_to_base_type 
    value = _BaseValue(self._call_to_base_type(value)) 
    File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/ext/ndb/model.py", line 1198, in _call_to_base_type 
    return call(value) 
    File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/ext/ndb/model.py", line 1274, in call 
    newvalue = method(self, value) 
    File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/ext/ndb/model.py", line 1695, in _validate 
    (value,)) 
BadValueError: Expected string, got comment(content=u'dasdsad', date=u'', name=u'', title=u'') 
+0

의견 객체의 표현을 게시 한 오류는 무엇입니까? –

+0

죄송합니다. 편집하십시오 BadValueError : 예상 문자열, 주석이 있습니다. (key = Key ('comment', 5659645909663744), content = u'dasdsad ', date = u' ', name = u' ', title = u '') – user3376321

+0

stacktrace point가'report.comments.append (new_comment)'코드 라인에 있다고 가정합니까? –

답변

2

우리는 지금

class report(ndb.Model): 
    comments=ndb.StructuredProperty(comment,repeated=True) 
    date=ndb.StringProperty() 
    title=ndb.StringProperty() 
    content=ndb.BlobKeyProperty() 
    comments=ndb.StringProperty(repeated=True) 
    images=ndb.BlobKeyProperty(repeated=True) 
    images_urls=ndb.StringProperty(repeated=True) 
    status=ndb.BooleanProperty() 

이 문제를 볼 수있는 문제를 볼 수 있습니다.

당신은 두 번 comments를 정의하고, 두 번째 정의가 사용됩니다 유일한 하나입니다. 당신은

당신은 당신이 제공 한 정보의 정확성이 얼마나 중요한지 볼 수행합니다 StringProperty로 의견을 재정의했다.

정확한 오류를 알려주는 오류 메시지가 발생했습니다.

+0

와우 OMG, 실제로 나는 그것을 알아 채지 못한다. 고맙다. – user3376321

+1

Tim Hoffman이 최고 다. – user3376321

+0

나는 투표 할 생각이 없다. 너는 많이 낭비했다. 귀하의 초기 질문에 올바른 코드와 스택 트레이스를 포함하지 않음으로써 시간이 많이 걸릴 것입니다. –