Skip to content
Closed
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions gcloud/datastore/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,3 +346,30 @@ def with_cursor(self, start_cursor, end_cursor=None):
if end_cursor:
self._pb.end_cursor = base64.b64decode(end_cursor)

def order(self, *properties):

This comment was marked as spam.

"""Adds a sort order to the query. If more than one sort order is added,
they will be applied in the order specified.

:type properties: string
:param properties: String giving the name of the property on which to sort,
optionally preceded by a hyphen (-) to specify descending order.
Omitting the hyphen specifies ascending order by default.

:rtype: :class:`Query`
:returns: A Query order by properties.
"""
clone = self._clone()

for p in properties:
property_order = clone._pb.order.add()

if p.startswith('-'):
property_order.property.name = p[1:]
property_order.direct = property_order.DESCENDING
else:
property_order.property.name = p
property_order.direction = property_order.ASCENDING

return clone