In Google App Engine, datastore modelling, I would like to ask how can I check for null value of a property with class UserProperty? for example: I have this code:
class Entry(db.Model):
title = db.StringProperty()
description = db.StringProperty()
author = db.UserProperty()
editor = db.UserProperty()
creationdate = db.DateTimeProperty()
When I want to check those entries that have the editor is not null, I can not use this kind of GqlQuery
query = db.GqlQuery("SELECT * FROM Entry " +
"WHERE editor IS NOT NULL" +
"ORDER BY creationdate DESC")
entries = query.fetch(5)
I am wondering if there is any method for checking the existence of a variable with UserProperty? Thank you!
query = db.GqlQuery("SELECT * FROM Entry WHERE editor > :1",None)
However, you can't ORDER BY
one column and have an inequality condition on another column: that's a well-known GAE limitation and has nothing to do with the property being a UserProperty nor with the inequality check you're doing being with None.
Edit: I had a != before, but as @Nick pointed out, anything that's != None is > None, and > is about twice as fast on GAE (since != is synthesized by union of < and >), so using > here is a worthwhile optimization.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With