我创建了一个自定义db.Property
子类:
class PropertyFoo(db.StringProperty):
def validate(self, value):
# Yes this is a pointless validator, but please read on
return value
def get_value_for_datastore(self, model_instance):
return super(PropertyFoo, self).get_value_for_datastore(model_instance)
def make_value_from_datastore(self, value):
return super(PropertyFoo, self).make_value_from_datastore(value)
现在我还创建了一个db.Model
子类:
class ModelFoo(db.Model):
foo = PropertyFoo(required=True)
所以我测试了它们:
>>> m = ModelFoo()
# No errors :(
>>> m.foo
# No errors still
>>> print m.foo
'None' # <-- Why???
我应该期待一个错误,如:
BadValueError: Property foo is required
我如何确保我的自定义Property
子类,当它是时required
,会引发一个BadValueError
?我在我的PropertyFoo
定义中遗漏了什么吗?