On Feb 10, 7:06 pm, David Symonds <[email protected]> wrote:
> On Tue, Feb 10, 2009 at 9:45 AM, Jason DeFontes <[email protected]> wrote:
>
> > Is there a simple way to have a calculated property that automatically
> > updates itself any time an entity is saved? For example:
>
> > class Article(db.Model):
> >  body = db.StringProperty()
> >  word_count = db.IntegerProperty()
>
> You should override the put method:
>
> class Article(db.Model):
>   body = db.StringProperty()
>   word_count = db.IntegerProperty()
>
>   def put(self):
>     self.word_count = ComputeWordCount(self.body)  # or whatever
>     return super(Article, self).put()
>
> Dave.

Just be aware that Model.put() won't be called when you batch-save
your entities with db.put() function.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to