这个看似完美的Google App Engine代码因KindError而失败。
# in a django project 'stars'
from google.appengine.ext import db
class User(db.Model):
pass
class Picture(db.Model):
user = db.ReferenceProperty(User)
user = User()
user.put()
picture = Picture()
picture.user = user
# ===> KindError: Property user must be an instance of stars_user
google.appengine.ext.db.ReferenceProperty.validate中引发了异常:
def validate(self, value):
...
if value is not None and not isinstance(value, self.reference_class):
raise KindError('Property %s must be an instance of %s' %
(self.name, self.reference_class.kind()))
...
答案 0 :(得分:1)
原来我在admin.py中导入模型为
from frontend.stars.models import Star
此行污染了Star
的模块名称空间,isinstance
查询失败。
>>> user.__class__
<class 'frontend.stars.models.User'>
>>> Picture.user.reference_class
<class 'stars.models.User'>