Book Image

Mastering Google App Engine

Book Image

Mastering Google App Engine

Overview of this book

Table of Contents (18 chapters)
Mastering Google App Engine
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Sorting


Now we are comfortable with querying the data, it is time to put it in some desirable order. That is, sorting the results. How do we do that? Our old friend search.QueryOptions takes a keyword argument called sort_options. We just have to supply that and we are done. Okay, so the question is what this sort_options argument would be?

It's actually an instance of search.SortOptions class which takes a single argument called expressions. What is expressions then? It is just a list of search.SortExpression instances where search.SortExpression constructor takes some keyword arguments which define the sorting behavior.

All this seems bit complicated so let's take another look.

  • Whenever you are going to sort, you are either going to sort on a field or a calculated value. For example, you might want to sort on price, which is just a field or price per square feet that is a calculated field obtained by dividing price to size field.

  • But that was just for the value but as we know it is not mandatory...