Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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.

share|improve this question
    
I thought about saving the query in the model class, and do all sorts of dirty queries on that level, is there a better way? –  Mohamed Khamis Dec 20 '11 at 22:32

2 Answers 2

up vote 4 down vote accepted

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

share|improve this answer
1  
Excellent. How come this isn't documented? –  Daniel Roseman Dec 21 '11 at 9:32
    
Yea wonder the same, thanks for sharing =) –  ib.lundgren Dec 21 '11 at 15:11

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)
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.