Hey Matt,
I would expect you to get an 'AttributeError' exception using
"number.numguess" since it is a query. If you're going to updated
guesses, you probably should be using a transaction. The pattern will
look something like this:
def txn():
number = db.get_by_key(number_key)
if not number:
# bad key! maybe raise an error
return False, -1
number.guesses += 1
number.put()
guessed_right = number.ans == their_guess
return guessed_right, number.guesses
correct, guesses = db.run_in_transaction(txn)
Robert
On Wed, Aug 24, 2011 at 17:02, Matt <[email protected]> wrote:
> I am trying to count how many times it takes someone to guess a random
> number. My db looks like this -
>
> class Answer(db.Model):
> ans = db.IntegerProperty()
> user = db.UserProperty()
> msg = db.StringProperty()
> numguess = db.IntegerProperty()
>
> numguess is the counter.
> Each time a guess passes a test to make sure it is an integer, I want
> to pull out numguess so I can add 1 to it before I let the user know
> what guess they are on and then put the updated number back into
> numguess.
>
> This is some code that executes when the user enters an integer
>
> number = Answer().all()
> logging.info("Got all")
> guesses = number.numguess
> logging.info("Got number of guesses: %s", str(guesses))
> guesses += 1
>
> In the logs I see the "Got all" info but that is it. I don't see the
> Got number of guesses: %s. It doesn't complete the
> guesses = number.numguess
>
> Why doesn't this work, and any idea on what I can change to pull the
> value in numguess out?
> Thanks.
>
> --
> 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.
>
>
--
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.