在一个汽车历史应用程序中,我必须创建不同的图表,其中一些车型可能会出现在一个或多个不同的图表中,如“最快的汽车”、“最好的汽车”等,然后它们必须在图表中排序。我使用StructuredProperty来创建标记名/顺序位置对。在
class CarTag(ndb.Model):
name = ndb.StringProperty()
position = ndb.IntegerProperty()
class Car(ndb.Model):
model_name = ndb.StringProperty()
trim = ndb.StringProperty()
year = ndb.IntegerProperty()
tags = ndb.StructuredProperty(CarTag, repeated=True)
structured属性上的过滤器工作正常。在
^{pr2}$但是为了得到有序的图表,我需要根据同一个结构属性的position属性对它们进行排序,这个属性的名称是“最快的汽车”。{按顺序读}(汽车标签位置)将仅按列表的第一个元素排序。在
cars = Car.query(Car.tags.name==name).order(Car.tags.position)
是否可以按特定结构属性的属性排序?在
不是你不能按StructuredProperty内部的一个属性排序,而是你的StructuredProperty是repeated=True。。。使其成为列表属性。。而且不能对列表属性进行可靠的排序:
https://cloud.google.com/appengine/docs/python/datastore/queries#properties_with_multiple_values_can_behave_in_surprising_ways
相关问题 更多 >
编程相关推荐