Hi

Something about what you have said here doesn't make sense.

Whilst objects aren't iterable lists are and so if you have a list of
datastore entities as a result of a fetch
then the code you showed will in fact work.


Assuming datelist is the result of a fetch.

Then the following will work.

dates = sorted(datelist, key=lambda x:
getattr(x,'comp_date',some_floor_or_ceiling_date))  # sentinal only
needed if you some entities without the property

The following example is directly from my local console

>>> w = qtrack.models.Worksheet.all().fetch(1000)
>>> list(w)
[<qtrack.models.worksheet.Worksheet object at 0x26a8910>,
<qtrack.models.worksheet.Worksheet object at 0x26a8a90>,
<qtrack.models.worksheet.Worksheet object at 0x26a8a50>,
<qtrack.models.worksheet.Worksheet object at 0x26a8b10>,
<qtrack.models.worksheet.Worksheet object at 0x26a8bd0>]
>>> dates = sorted(w,key=lambda x: getattr(x,'date_created'))
>>> dates
[<qtrack.models.worksheet.Worksheet object at 0x26a8910>,
<qtrack.models.worksheet.Worksheet object at 0x26a8b10>,
<qtrack.models.worksheet.Worksheet object at 0x26a8a90>,
<qtrack.models.worksheet.Worksheet object at 0x26a8a50>,
<qtrack.models.worksheet.Worksheet object at 0x26a8bd0>]

No my model is based on Expando but that make no difference.

Rgds

T





On Apr 15, 8:17 pm, Lynge <como...@gmail.com> wrote:
> Hi, I am using an Expando class and I want to sort it.
> It needs to be sorted according to a dynamically assigned property so
> it has o be done at runtime.
>
> I am using python and it could be done easily with something like:
>
>         dates = sorted(datelist, key=itemgetter('comp_date'))
>
> But since the objects returned from the datastore are not iterable
> this is impossible.
>
> So I thought that I would just create my own list of dicts and then I
> can iterate and sort it, but alas that is not possible either.
>
> I can iterate over the primary just fine
>
>         for date in datesfromdb:
>             datelist.append(dict(date))
>
> but no matter how I try to get the data out of the date object I have
> no luck.
> I dont want to name all the properties of the model since that would
> make it a big pain to update anything, but how then do I do it?
>
> Any help would be appreciated.

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to google-appeng...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en.

Reply via email to