Google App Engine null sort order

女生的网名这么多〃 提交于 2020-01-06 05:41:19

问题


According to Googles Documentation, null values have no sort order. Is there any way to configure this behavior. For instance, if I am sorting an integer property in ascending order, can I configure the datastore to return null values last or first?


回答1:


Your best bet may be to save the property as a blank "" string for each entity that has a null value for that property. Be sure to run put() on each entity that you alter.

employees = Employee.all().fetch(50)
for employee in employees:
    if employee.hobbies is None: # Null value property
        employee.hobbies = ""
        employee.put()

Of course, this is not the most efficient way to perform this task. You may want to create a list object, like "batch_put_list," and append each employee object into the list. Then, perform a db.put(batch_put_list).

batch_put_list = []
employees = Employee.all().fetch(50)
for employee in employees:
    if employee.hobbies is None:
        employee.hobbies = ""
        batch_put_list.append(employee)
db.put(batch_put_list)

Hope this helps.



来源:https://stackoverflow.com/questions/10960094/google-app-engine-null-sort-order

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!