1

I have the following code:

employees = Employee.query()
employees = employees.filter(query.OR(Employee.passport_id == passport_id,
  Employee.inn == inn))
employees.order(-Employee.added)
results = employees.fetch(5)

But I am getting error:

NameError: global name 'query' is not defined

Btw, how will it work in case passport_id is None and Employee.passport_id is None. Will it find such match?

Upd. fixed first problem by adding

from google.appengine.ext.ndb import query 

Second question remains..

Charles
  • 50,943
  • 13
  • 104
  • 142
LA_
  • 19,823
  • 58
  • 172
  • 308

1 Answers1

1

You should use ndb.OR, so you won't need to import the query submodule (you should never have to import that).

If passport_id is a defined property, yes, querying for Employee.passport_id == None will work. (Be sure to use the '==' operator, not 'is'.)

Guido van Rossum
  • 16,690
  • 3
  • 46
  • 49
  • Thanks. With regards to the first part of the question - that's strange, since this is what given in the docs - https://developers.google.com/appengine/docs/python/ndb/queries#nest_and_or – LA_ Jul 03 '12 at 17:20
  • I've raised separate question about 2nd part - http://stackoverflow.com/questions/11316077/how-to-avoid-returning-of-none-values-with-gae-ndb – LA_ Jul 03 '12 at 17:28