views:

48

answers:

1

Hi,

I'm trying to use figure out how to sub query a query that uses a filter. From what I've figured out so far while using .filter() it changes the original query, that leads to a second .filter() would also have to match the first filter.

I would like to make something like this:

modules = data.Modules.all().filter('page = ', page.key())
modules.filter('name = ', 'Test')
modules.filter('name = ', 'Test2')

I can't get the "Test2" filter to work. The only solution I have at the moment is to make all new queries.

data.Modules.all().filter('page = ', page.key()).filter('name = ', "Test").get()
data.Modules.all().filter('page = ', page.key()).filter('name = ', "Test2").get()

Or write the same as an GQL. But for me it seams quite stupid way to go.

I've looked at using ancestors, but I don't quite understand it and honestly don't know if that's the way to go.

Any ideas?

..fredrik

+3  A: 

It appears that what you're trying to do is an OR query, which isn't supported in App Engine. You can use an IN query, which simulates this by doing multiple queries for you.

The reason the first thing you tried doesn't work is that you're trying to filter your query so that your results match both "Test" and "Test2", which obviously will never be true for a non-list property.

Wooble
Thanks. If I do query with the IN operator, how do a separate them? If I want to assign there result that matches "Test" to of object and "Test2" to another?
fredrik
Using the Query interface, just pass a python list of parameters to match. If you want the matches in different objects instead of a list of results, you'll need to do 2 completely separate queries, the same as with any database engine.
Wooble
First off, you seems to be on top of all my questions. Thanks. :)Since I only need another StringProperty in corresponding to what name is, I'm using the IN operator to get them all the make an dict of it. Then I can just use it with modules.Test, modules.Test2. Thanks!
fredrik