开发者

Search by a property of a reference

开发者 https://www.devze.com 2023-01-15 06:19 出处:网络
I have the following models: class Station(db.Model): code = db.StringProperty(required=True) name = db.StringProperty(required=True)

I have the following models:

class Station(db.Model):
    code = db.StringProperty(required=True)
    name = db.StringProperty(required=True)

class Schedule(db开发者_高级运维.Model):
    tripCode = db.StringProperty(required=True)
    station = db.ReferenceProperty(Station, required=True)    
    arrivalTime = db.TimeProperty(required=True)
    departureTime = db.TimeProperty(required=True)

How can I order programatically all the Schedules by Station's name?

Something like Schedule.all().order('station.name')


You will to de-normalize your models or sort the results in memory:

Schedule.all().fetch(100).sort(key=lambda s: s.station.name)

(code not tested)


After use sort i think you need to fetch all entities:

Schedule.all().fetch (100).sort(key=lambda s: s.station.name)

May be you can also use collection name. But i think the jbochi answer is better :)

[x.schedule_set.get () for x in Station.all ().order ('name')]
0

精彩评论

暂无评论...
验证码 换一张
取 消