class ModelWithComputedProperty(Model): s = props.String() def compute(self): return self.s.upper() if self.s else None c = props.Computed(compute)
class ModelWithComputedProperty3(Model): calls = [] def __compute(self): self.calls.append(1) return 42 c = props.Computed(__compute)
class Post(Model): author = props.Key(indexed=True, kind=User) title = props.String() def __compute_slug(self): if self.title is None: return None return slugify(self.title) def __compute_body(self): if self.body is None: return None return markdown(self.body) slug = props.Computed(__compute_slug) body = props.Text() body_markdown = props.Computed(__compute_body) tags = props.String(indexed=True, repeated=True) created_at = props.DateTime(indexed=True, auto_now_add=True) updated_at = props.DateTime(indexed=True, auto_now=True)
class ModelWithComputedProperty2(Model): c = props.Computed(lambda s: 42)
class ModelWithComputedProperty1(Model): c = props.Computed(f)