Mohamed Khamis
Mohamed Khamis

Reputation: 8029

Use an SQL-like function with GAE's datastore

I have a property (isFull) in a model whose value depends on other properties in that same model (counter).

So far I've been setting the property's value myself whenever any of the properties it depends on change. I wrote a function isFull() that checks the counter and returns True or False. But I can't use it with a query unless I fetch everything then iterate over the results checking if any of them isFull, which is BAD I know..

Is there a way to use my function with filter or gql ? or is there a different way of doing it? I know I can use a filter to check the counter but it goes more complex than that in some cases where I need to check dates, a counter and another flag all at the same time.

Upvotes: 0

Views: 130

Answers (2)

Nick Johnson
Nick Johnson

Reputation: 101139

Use a ComputedProperty to store your computed value as a property in the datastore that you can filter on.

Upvotes: 4

ib.lundgren
ib.lundgren

Reputation: 1544

I don't know how to automatically recalculate a property when another has changed. While you could hide some of the updating by creating a custom property you would still have to manually update it when you are updating properties it depends on.

You might instead want to make the need for the isFull property obsolete by chaining the filtering, something along the lines of

query.filter('counter >', 42)
query.filter('created <', datetime(2011,12,21))
query.filter('created >', datetime(2011,12,19))
query.filter('myflag =', true)

Upvotes: 0

Related Questions