Guest User

Untitled

a guest
Jul 19th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. class PropertyFoo(db.StringProperty):
  2. def validate(self, value):
  3. # Yes this is a pointless validator, but please read on
  4. return value
  5.  
  6. def get_value_for_datastore(self, model_instance):
  7. return super(PropertyFoo, self).get_value_for_datastore(model_instance)
  8.  
  9. def make_value_from_datastore(self, value):
  10. return super(PropertyFoo, self).make_value_from_datastore(value)
  11.  
  12. class ModelFoo(db.Model):
  13. foo = PropertyFoo(required=True)
  14.  
  15. >>> m = ModelFoo()
  16. # No errors :(
  17. >>> m.foo
  18. # No errors still
  19. >>> print m.foo
  20. 'None' # <-- Why???
  21.  
  22. BadValueError: Property foo is required
  23.  
  24. class PropertyFoo(db.StringProperty):
  25. def validate(self, value):
  26. super(PropertyFoo, self).validate(value) #Base implementation checks
  27. #Do your other check here raising BadValueError
  28. return value
Add Comment
Please, Sign In to add comment