更新
这是我创建以下方案的最大努力
user = self.auth.store.user_model.create_user(email,
password_raw=newpasswd)
if not user[0]: # user is a tuple
return user[1] # Error message
else:
# User is created, let's try making the references
okuser = auth_models.User.get_by_id(long(user[1].key.id()))
okuser.sponsor = auth_models.User.get_by_id(long(sponsor_id)).auth_ids
原始问题
如何使用 expando 类进行自我引用以指示哪个用户是哪个用户的“赞助商”?“赞助商”是邀请新用户的人,因此在创建时我们必须存储它,并且将其存储为引用属性比字符串或字符串列表要简洁得多。
我可以创建一个新用户,但我不知道如何进行引用,以便我可以告诉一个用户谁是另一个用户谁是第一个用户的赞助商,我想一种建模方法是使用 selfreferenceproperty 因为两者对象是用户,但复杂之处在于它是一个扩展模型,所以我不知道如何使用引用属性。你能告诉我怎么做或给我一个线索,我怎样才能以最好的方式解决这个问题?
user = self.auth.store.user_model.create_user(email,
password_raw=newpasswd)
if not user[0]: # user is a tuple
return user[1] # Error message
else:
# User is created, let's try making the reference
okuser = auth_models.User.get_by_id(user[1].key.id())
okuser.sponsor = db.SelfReferenceProperty(User,
collection_name='matched_images', verbose_name='Sponsor')
我不知道如何做最后一部分,用 epando 模型存储实际的参考属性。如何做呢?
更新
似乎无法做到:
NotImplementedError: Property sponsor does not support <class 'google.appengine.ext.db.ReferenceProperty'> types.
代码:
user = self.auth.store.user_model.create_user(email,
password_raw=newpasswd)
if not user[0]: # user is a tuple
return user[1] # Error message
else:
# User is created, let's try redirecting to login page
okuser = auth_models.User.get_by_id(long(user[1].key.id()))
okuser.sponsor = db.SelfReferenceProperty(auth_models.User.get_by_id(sponsor_id),collection_name='matched_distributor')
okuser.put()
它迫使我使用字符串而不是引用,然后解决方案是可行的:
user = self.auth.store.user_model.create_user(email,
password_raw=newpasswd)
if not user[0]: # user is a tuple
return user[1] # Error message
else:
# User is created, let's try redirecting to login page
okuser = auth_models.User.get_by_id(long(user[1].key.id()))
okuser.sponsor = sponsor_id
okuser.put()