[google-appengine] Re: How to filter date

2011-04-01 Thread nickmilon
you need something like:

News.all().filter('created_at.month >',datetime(2011,3,31,23,59))

but..

your result set will be ordered primarily on created_at coz you are
using an inequality filter, if you do not mind that then ok.

IMHO a better solution to your problem would be if you use an equality
filter based on a computed property:

class BaseArticleModel(polymodel.PolyModel):
title = db.StringProperty()
created_at = db.DateProperty(auto_now_add=True)
updated_at = db.DateProperty(auto_now=True)
@db.ComputedProperty
def CM(self):return self.created_at.month

then you can filter on an equality which is much more convenient for
the query at the expense of a little overhead on storage and put
latency:

q = News.all().filter('CM =',1)


happy coding;)


On Apr 1, 7:20 pm, walter  wrote:
> My model
>
> class BaseArticleModel(polymodel.PolyModel):
>     title = db.StringProperty()
>     created_at = db.DateProperty(auto_now_add=True)
>     updated_at = db.DateProperty(auto_now=True)
>
> class News(BaseArticleModel):
>     body = db.TextProperty()
>
> I ned get rows by last month. When to do filter like this
>
> q = News.all().filter('created_at.month = ',
> datetime(2011,04,01).month)
>
> I get "IndexError: The query returned fewer than 1 results"

-- 
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-appengine@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.



[google-appengine] Re: How to filter date

2011-04-01 Thread walter
Thank you very much. This is a very useful and helped. But, I've bit
confused.  I didn't find any references to @db.ComputedProperty. :(

-- 
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-appengine@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.



[google-appengine] Re: How to filter date

2011-04-02 Thread nickmilon
although  you can find it here:
http://googleappengine.googlecode.com/svn/trunk/python/google/appengine/ext/db/__init__.py
I agree it is not well documented, although it it very useful, since
it behaves as all other properties (can be included in indexes etc.)

:-)

On Apr 2, 1:14 am, walter  wrote:
> Thank you very much. This is a very useful and helped. But, I've bit
> confused.  I didn't find any references to @db.ComputedProperty. :(

-- 
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-appengine@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.