Query.filter() questions

6 views
Skip to first unread message

Felippe Bueno

unread,
Jul 25, 2010, 8:31:23 PM7/25/10
to google-a...@googlegroups.com
Hello people.

3 questions:
1. is it possible to filter an property inside the Entity property?
For example:
Article(author = users.get_current_user(), skey='monmon').save()
Invite(author = users.get_current_user(), entry = Article.get('monmon')).save()

##here is the filter
invites = Invite.all().filter('entry.author =', user.get_current_user())

2. Is it possible to pass some thing like 'or' to filter ?
Some thing like this:
articles = Article.all().filter('author =',
user.get_current_user()).or('user =', user.get_current_user())

3. (not a query question). Some one know if GAE offers some kind of
facility to an invite/collaboration system ?
I need to invite google users to edit or comment on my system.

Thanks

Cheers

Geoffrey Spear

unread,
Jul 26, 2010, 9:19:07 AM7/26/10
to Google App Engine


On Jul 25, 8:31 pm, Felippe Bueno <felippe.bu...@gmail.com> wrote:
> Hello people.
>
> 3 questions:
> 1. is it possible to filter an property inside the Entity property?
> For example:
> Article(author = users.get_current_user(), skey='monmon').save()
> Invite(author = users.get_current_user(), entry = Article.get('monmon')).save()
>
> ##here is the filter
> invites = Invite.all().filter('entry.author =', user.get_current_user())

No, you can only filter on actual indexed properties. To get this
functionality, you'll need to denormalize and store entry's author
property as a property in the Invite entity at write-time. Note that
for this to work you'll also need to arrange for this property to be
updated when you change the corresponding Article entity.

>
> 2. Is it possible to pass some thing like 'or' to filter ?
> Some thing like this:
> articles = Article.all().filter('author =',
> user.get_current_user()).or('user =', user.get_current_user())

No, the datastore doesn't support OR queries. You'll need to execute
multiple queries and join the results yourself.

Massimiliano

unread,
Jul 26, 2010, 11:45:37 AM7/26/10
to google-a...@googlegroups.com
Hi,
I want to add a question. Can I do something like that:

filtro = PRINC.all()
filtro.filter('code= ', self.request.get('var'))

and if I can't how can I do it? 
var
is the input of a text box.

Massimiliano

2010/7/26 Geoffrey Spear <geoff...@gmail.com>

--
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-a...@googlegroups.com.
To unsubscribe from this group, send email to google-appengi...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en.




--

My email: massimilia...@gmail.com
My Google Wave: massimilia...@googlewave.com

Robert Kluin

unread,
Jul 26, 2010, 12:53:54 PM7/26/10
to google-a...@googlegroups.com
Yes. But you need a space between the field name and operator:
filtro.filter('code = ', self.request.get('var'))


Robert

Felippe Bueno

unread,
Aug 3, 2010, 6:54:17 PM8/3/10
to google-a...@googlegroups.com
>> 2. Is it possible to pass some thing like 'or' to filter ?
>> Some thing like this:
>> articles = Article.all().filter('author =',
>> user.get_current_user()).or('user =', user.get_current_user())
>
> No, the datastore doesn't support OR queries.  You'll need to execute
> multiple queries and join the results yourself.

Ok, Thanks.
I just find one way to 'join' the results:
entries = list(chain(Article.all().filter('public =',
False).filter('status =', True).filter('author =', user),
Article.all().filter('public =', True)))

trying:
entries = Article.all().filter('public =', False).filter('status =',
True).filter('author =', user)
entries += Article.all().filter('public =', True)
don't work.


There is a better way to join the results ?

Reply all
Reply to author
Forward
0 new messages