Re: [google-appengine] Working with Query results
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 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 : > > 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: > > ${result.mUNIQUE} (${result.mCOUNT}) > > % 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 google-appeng...@googlegroups.com. > > To unsubscribe from this group, send email to > google-appengine+unsubscr...@googlegroups.com > . > > 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 google-appeng...@googlegroups.com. > To unsubscribe from this group, send email to > google-appengine+unsubscr...@googlegroups.com > . > 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 google-appeng...@googlegroups.com. To unsubscribe from this group, send email to google-appengine+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en.
Re: [google-appengine] Working with Query results
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 : > 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: > ${result.mUNIQUE} (${result.mCOUNT}) > % 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 google-appeng...@googlegroups.com. > To unsubscribe from this group, send email to > google-appengine+unsubscr...@googlegroups.com. > 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 google-appeng...@googlegroups.com. To unsubscribe from this group, send email to google-appengine+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en.
Re: [google-appengine] Working with Query results
Hi Zeynel, I don't use templates but as a guess i think you use result.mCOUNT To sort you can read the result in a list and sort on this or maybe the template engine has a solution for this. gr wim On Wed, Nov 10, 2010 at 2:56 PM, Zeynel wrote: > 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: > ${result.mUNIQUE} (${result.mCOUNT}) > % 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 google-appeng...@googlegroups.com. > To unsubscribe from this group, send email to > google-appengine+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/google-appengine?hl=en. > > -- gr wdo Demo free E-business: https://e-comm.appspot.com Wim den Ouden Google App Engine (cloud) -- You received this message because you are subscribed to the Google Groups "Google App Engine" group. To post to this group, send email to google-appeng...@googlegroups.com. To unsubscribe from this group, send email to google-appengine+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en.