def gql(cls, query_string, *args, **kwds):
"""Returns a polymorphic query using GQL query string.
This query is polymorphic in that it has its filters configured in a way
to retrieve instances of the model or an instance of a subclass of the
model.
Args:
query_string: properly formatted GQL query string with the
'SELECT * FROM <entity>' part omitted
*args: rest of the positional arguments used to bind numeric references
in the query.
**kwds: dictionary-based arguments (for named parameters).
"""
if cls == cls.__root_class__:
return super(PolyModel, cls).gql(query_string, *args, **kwds)
else:
from google.appengine.ext import gql
query = db.GqlQuery('SELECT * FROM %s %s' % (cls.kind(), query_string))
query_filter = [('nop',
[gql.Literal(cls.class_name())])]
query._proto_query.filters()[('class', '=')] = query_filter
query.bind(*args, **kwds)
return query
评论列表
文章目录