This is unrelated but you will probably want to read the Python coding style guide:
http://www.python.org/dev/peps/pep-0008/ It's bad form to name your instance variables the way they're named in your sample code. -- Ikai Lan Developer Programs Engineer, Google App Engine Blogger: http://googleappengine.blogspot.com Reddit: http://www.reddit.com/r/appengine Twitter: http://twitter.com/app_engine On Wed, Nov 10, 2010 at 4:53 PM, djidjadji <[email protected]> wrote: > RESULTS = QUERY.fetch(10) > RESULTS.sort(key=lambda x: x.mDATE.toordinal() * x.mCOUNT) > > What is a "list of model instances? > You can start by learning some basic python. Read the tutorial on the > python.org website, or in the help file (on windows platform) > > 2010/11/10 Zeynel <[email protected]>: > > Can someone help me understand how to access the results of a query? > > > > This is my model: > > > > class Rep(db.Model): > > mAUTHOR = db.UserProperty(auto_current_user=True) > > mUNIQUE = db.StringProperty() > > mCOUNT = db.IntegerProperty() > > mDATE = db.DateTimeProperty(auto_now=True) > > mDATE0 = db.DateTimeProperty(auto_now_add=True) > > mWEIGHT = db.IntegerProperty() > > > > The app has a textarea form and user submits repetitions. mCOUNT is > > the number of repetitions. I use this query to display top ten reps: > > > > QUERY = Rep.all() > > QUERY.filter("mAUTHOR =", user) > > QUERY.order("-mCOUNT") > > RESULTS = QUERY.fetch(10) > > > > I display the results with Mako template: > > > > % for result in RESULTS: > > <p>${result.mUNIQUE} (${result.mCOUNT})</p> > > % endfor > > > > Instead of sorting by mCOUNT I want to sort by mWEIGHT so that an old > > item with high count should be lower than a new item with lower count. > > But the precise weighing formula is not important at this point. For > > instance, it may be > > > > mWEIGHT = mDATE * mCOUNT > > > > What I do not understand is, how do I access mDATE and mCOUNT to put > > them in the formula? I am having difficulty, in general, visualizing > > the result of a query. The tutorial > > > http://code.google.com/appengine/docs/python/datastore/creatinggettinganddeletingdata.html#Getting_Entities_Using_a_Query > > says that the query returns "the requested results as a list of model > > instances." What is a "list of model instances?" And how to access > > them as a variables in this context. 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]<google-appengine%[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]<google-appengine%[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.
