python appengine
python appengine

Reputation: 35

Google App Engine Python adding

class Config(db.Model):

    Latest = db.IntegerProperty()

    class New(webapp.RequestHandler): 
        def get(self): 
            config = Config()
            Last = Config.Latest
            t = Last + 1

returns

t = LastUUID + ADDNUM
TypeError: unsupported operand type(s) for +: 'IntegerProperty' and 'Int'

What im trying to do is get the int from the datastore and app 1 to it. Then reassign the int in the datastore. I have no clue why it is throwing these errors. I even tried t = int(Last +1). UPDATE: This is what i needed and solved my problem. http://code.google.com/appengine/articles/sharding_counters.html

Upvotes: 1

Views: 379

Answers (4)

python appengine
python appengine

Reputation: 35

http://code.google.com/appengine/articles/sharding_counters.html

This is a basic conter that can be updated multiple times a second. Works perfect

Upvotes: 0

Chris B.
Chris B.

Reputation: 90329

This has nothing to do with Google App Engine or Django. In the following code:

class X(object):
    @property
    def y(self):
        return 5

x = X()
print X.y + 5

... you get the same error. X.y refers to the unbound property on the class object. x.y refers to the bound property, and indeed in the above example print x.y + 5 prints "10".

Change the line to Last = config.Latest and it should work. And I strongly recommend you take up the recommendations in PEP 8, particularly under "Prescriptive: Naming Conventions". Generally speaking, in Python classes should use CapWords, while functions and variables should use lowercase_with_underscores.

Upvotes: 1

Thomas K
Thomas K

Reputation: 40390

The changes you need are more than tweaking a single line.

You need some sort of initialisation function which will create a Config() instance, assign Latest an initial value (like 1 or 0) and store it in the datastore.

Then your RequestHandler needs to execute a query to retrieve the relevant Config instance. Finally, update Latest, and save the instance into the datastore again.

Upvotes: 3

Falmarri
Falmarri

Reputation: 48605

The syntax you're looking for is

t = int(Last) +1

However, I'm not sure that's what you want to do. I don't know django or whatever framework this is so it's hard to say. But in python, types must be compatible for you to add them.

Upvotes: 0

Related Questions