Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6615539
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:28:26+00:00 2026-05-25T20:28:26+00:00

In Appengine, I am trying to have a property value computed automatically and stored

  • 0

In Appengine, I am trying to have a property value computed automatically and stored with the object.

I have a class, Rectangle, and it has a width, height and area. Obviously the area is a function of width and height, but I want it to be a property because I want to use it for sorting. So I try to modify the put() function to sneak the area in when storing the Rectangle like so:

class Rectangle(db.Model):
    width   = db.IntegerProperty()
    height  = db.IntegerProperty()
    area    = db.IntegerProperty()

    def put(self, **kwargs):
        self.area = self.width * self.height
        super(Rectangle, self).put(**kwargs)

This works when I invoke put() on the Area object directly:

re1 = Rectangle(width=10, height=10)
re1.put()
print re1.area      # >> 10

But when I use db.put() (e.g. to save a lot of them at once), this breaks.

re2 = Rectangle(width=5, height=5)
db.put(re2)
print re2.area      # >> None

What is the proper way to ‘sneak in’ the computed value?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T20:28:27+00:00Added an answer on May 25, 2026 at 8:28 pm

    Don’t override put – as you observe, it’s fragile, and doesn’t get invoked if you call db.put instead of the model’s put function.

    Fortunately, App Engine provides a ComputedProperty which makes your use-case really easy:

    class Rectangle(db.Model):
        width   = db.IntegerProperty()
        height  = db.IntegerProperty()
    
        @db.ComputedProperty
        def area(self):
          return self.width * self.height
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been using django-appengine and am now trying a project with django-nonrel. Before
I'm trying to do the python tutorial here http://code.google.com/appengine/docs/python/gettingstarted/helloworld.html (I have python 2.5 installed)
I have the following class that I'm trying to make persistent, and am getting
I am trying to use google appengine. I have this model: def Human(db.Model): name
I have been trying for 4 days to get app-engine and grails working together
I'm trying to get Google AppEngine to work on my Debian box and am
I'm trying to deploy a java application to appspot (google appengine). I'm new to
I am working in python on appengine. I am trying to create what is
I have a Model in an existing Datastore. Which looks like this: class SomeKind(db.Model):
I have a weird error in my code. I'm trying to read some characters

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.