views:

31

answers:

2

After running a query on the datastore, I copy the results to a new list as I interrogate, merge and prune the results. When I'm finished, I'd like to sort the new list, but I'm seeing the following error...

TypeError: 'LiveRouteStatus' object is unsubscriptable

LiveRouteStatus is a Model class that I query, and while the actual code is more complicated, here's a shortened version of what I'm doing...

class LiveRouteStatus(db.Model):
    dateAdded = db.DateTimeProperty(autho_now_add=True)
    stopID    = db.StringProperty()
    time      = db.IntegerProperty()

q = db.GqlQuery("select * from LiveRouteStatus where stopID = :1 order by dataeAdded desc limit 24", stopID)

route_results = []
for r in routes:
    if magic_test_works:
        route_results.append(r)

sorted(route_results, key=itemgetter('time')

Is there some basic element of Python that I'm screwing up here? Or is this an indexing issue with the Model class?

+3  A: 

itemgetter('time') is like saying ['time'].

You want attrgetter('time'), which is like .time.

Ned Batchelder
This solved the error... However, it doesn't actually sort. :( Do I need to write my own sort function since it isn't an integer (but rather of type db.IntegerProperty?
Greg
head hanging in shame... i failed to assign the results of the sorted() call.
Greg
No shame, we've all done that..
Ned Batchelder
A: 

You are querying LiveRouteStatus and the class you declared is called LiveVehicleStatus. Not sure if this could be the reason tho !

Martin
that was a typo in the writeup... fixed it. thanks.
Greg