What you want is that there is only one TotalDistance object in the datastore.
Just as Alexander points out that you have an attribute name that is
the same as a
method of the class Query. And you must execute the query to get objects.
Better code is the following, in your post() method:
You must increment the count in a transaction, to avoid loosing a
count when two users simultaneous want to increment.

def txn(key, increment):  # defined inside the post() method
    tdObject = db.get(key)
    tdObject.count += increment
    tdObject.put()

tdObject = TotalDistance.get_or_insert('totalDist')
tempDistance = int(self.request.get('distance'))
db.run_in_transaction(txn, tdObject.key(), tempDistance)


2009/2/14 Neversummer <[email protected]>:
>
> I am new to app engine and pyton and unfortunately am not able to
> accomplish a seemingly simple task - thanks for your patience.
>
> I want to store a total miles value, which I am doing in model
> TotalDistance. As each new entry is submitted I want to increment that
> value. So I am getting the total value, then simply trying to add the
> new entry to the existing total. I've tried this a number of different
> ways, but keep getting the same error.
>
>
> // This is how I have defined TotalDistance
> class TotalDistance(db.Model):
>        count = db.IntegerProperty(required=True, default=0)
>
>
> // Here's the offending code
> //---  this all resides in def post(self) ---//
> tdResult = TotalDistance.all()
> tdCurr = tdResult.count
> tempDistance = int(self.request.get('distance')) # from the form
> tdMod = tdCurr+tempDistance
> putTotal = TotalDistance(
>           total = tdMod
>        )
> putTotal.put()
>
> // and the error
> receive the following error:
>
>  tdMod = tdCurr+tempDistance
> TypeError: unsupported operand type(s) for +: 'instancemethod' and
> 'int'
>
>
> Thanks for your help.

--~--~---------~--~----~------------~-------~--~----~
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