def OrderSet(self, value):
    # Since we wish to control which queries are made, we only accept values
    # from our custom Enum type Order.
    if not isinstance(value, Order):
      raise TypeError('Expected an enum, received: %s.' % (value,))

    # For MYFIRST, we order by attr1.
    if value == Order.MYFIRST:
      # Use the method OrderSet from the parent class to set the string value
      # based on the enum.
      super(MyModel, self).OrderSet('attr1')
    # For MYSECOND, we order by attr2, but in descending order.
    elif value == Order.MYSECOND:
      # Use the method OrderSet from the parent class to set the string value
      # based on the enum.
      super(MyModel, self).OrderSet('-attr2')
    # For either case, the order used here will be combined with an equality
    # filter based on the current user, and we have the corresponding indexes
    # specified in index.yaml so no index errors are experienced by our users.

    # If the value is not a valid Enum value, raise a TypeError. This should
    # never occur since value is known to be an instance of Order.
    else:
      raise TypeError((value,) % 'Unexpected value of Order: %s.')

  # This EndpointsAliasProperty is our own helper property and overrides the
  # original "order". We specify the setter as the function OrderSet which we
  # just defined. The property_type is the class Order and the default value of
  # the alias property is MYFIRST.

  # Endpoints alias properties must have a corresponding property type, which
  # can be either a ProtoRPC field or a ProtoRPC message class or enum class.
  # Here, by providing a property type of Order, we aid in the creation of a
  # field corresponding to this property in a ProtoRPC message schema.

  # The EndpointsAliasProperty can be used as a decorator as is done here, or
  # can be used in the same way NDB properties are, e.g.
  #   attr1 = ndb.StringProperty()
  # and the similar
  #   order = EndpointsAliasProperty(OrderGet, setter=OrderSet, ...)
  # where OrderGet would be the function defined here.
dataset/ETHPy150Open GoogleCloudPlatform/endpoints-proto-datastore/examples/matching_queries_to_indexes/main.py/MyModel.OrderSet/swapped operands of `%`