我无法正确地保存(或放置())模型。有趣的是,模型在它工作之前执行非常类似的保存。以下是代码的相关部分。在两个日志记录点,第一个正确返回用户的电子邮件。但是,第二个导致错误AttributeError: 'NoneType' object has no attribute 'c_user'
。显然,设置和取消设置变量并不是正确的做事方式,我只是添加了这些来解决问题,发现模型没有被保存。有什么建议?非常感谢!
class Source(db.Model):
current_user = db.UserProperty()
class SourceMember(db.Model):
c_user = db.UserProperty()
x_position = db.IntegerProperty()
y_position = db.IntegerProperty()
...
user = users.get_current_user()
if user:
source_key = self.request.get('g')
if not source_key:
source_key = user.user_id()
source = Source(key_name = source_key,
current_user = user)
source.put()
else:
source = Source.get_by_key_name(source_key)
source = None
source = Source.get_by_key_name(source_key)
logging.warning(source.current_user)
if source:
sourceMember = SourceMember.get_by_key_name(user.user_id() + source_key)
if not sourceMember:
sourceMember = SourceMember(parent = source.key(),
key_name = user.user_id() + source_key,
c_user = user,
x_position = None,
y_position = None)
sourceMember.put()
sourceMember = None
sourceMember = SourceMember.get_by_key_name(user.user_id() + source_key)
logging.warning(sourceMember.c_user)
答案 0 :(得分:1)
当您创建SourceMember时,您将为其提供父级,但是当您获得它时,父级将丢失。 Source没有父级,所以只能从它的id中获取它。