Not clear about the dot notation

Z

Zeynel

What does vote.vote refer to in this snippet?

def txn():
quote = Quote.get_by_id(quote_id)
vote = Vote.get_by_key_name(key_names = user.email(), parent =
quote)
if vote is None:
vote = Vote(key_name = user.email(), parent = quote)
if vote.vote == newvote:
return
quote.votesum = quote.votesum - vote.vote + newvote
vote.vote = newvote

from here: http://code.google.com/appengine/articles/overheard.html
 
T

TomF

What does vote.vote refer to in this snippet?

def txn():
quote = Quote.get_by_id(quote_id)
vote = Vote.get_by_key_name(key_names = user.email(), parent =
quote)
if vote is None:
vote = Vote(key_name = user.email(), parent = quote)
if vote.vote == newvote:
return
quote.votesum = quote.votesum - vote.vote + newvote
vote.vote = newvote

from here: http://code.google.com/appengine/articles/overheard.html

vote refers to the Vote instance.
vote.vote refers to the instance variable in that instance:
      vote: The value of 1 for like, -1 for dislike.

Confusing choice of names, in my opinion.

-Tom
 
I

Ian Kelly

What does vote.vote refer to in this snippet?

"vote" is an instance of the Vote class, and "vote.vote" is the value of
the "vote" attribute on that instance. In this case, that will be an int.

More precisely, "vote.vote" is a value managed by the "vote" descriptor
on the "Vote" class, a Google App Engine IntegerProperty.

Cheers,
Ian
 
Z

Zeynel

vote refers to the Vote instance.

So he must have instatiated previously like

vote = Vote()

is this correct?

So I have a model

class Item(db.Model):
title = db.StringProperty()
url = db.StringProperty()
date = db.DateTimeProperty(auto_now_add=True)
author = db.UserProperty()

and to write to the database I do

item = Item()
item.title = self.request.get("title")
item.url = self.request.get("url")
item.author = users.get_current_user()
item.put()
self.redirect("/newest")

so his vote.vote is like my item.url ?
 
T

TomF

So he must have instatiated previously like

vote = Vote()

is this correct?
Yes.


So I have a model

class Item(db.Model):
title = db.StringProperty()
url = db.StringProperty()
date = db.DateTimeProperty(auto_now_add=True)
author = db.UserProperty()

and to write to the database I do

item = Item()
item.title = self.request.get("title")
item.url = self.request.get("url")
item.author = users.get_current_user()
item.put()
self.redirect("/newest")

so his vote.vote is like my item.url ?

I believe so. Though you're now talking about an extension to db.Model
which looks like it's doing a lot more behind the scenes than a simple
variable access.

-Tom
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,166
Messages
2,570,902
Members
47,442
Latest member
KevinLocki

Latest Threads

Top