我无法让模型正确保存(或放置())。有趣的是,模型在工作之前会进行非常相似的保存。以下是代码的相关部分。在两个记录点,第一个正确返回用户的电子邮件。但是,第二个导致错误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)