[Zope] multi-column sort with ZCatalog
Michael Long
mlong@datalong.com
13 May 2003 09:47:16 -0400
Here is recipe for a python script that may help.
def multiSort(objects=None):
""" Sort a list of objects by one or more attributes """
if objects is None:
objects = []
return objects
results = []
sort_field = ['field1', 'field2', 'field3']
for object in objects:
row = [getattr(object, attr) for attr in sort_field]
row.append(object)
results.append(tuple(row))
results.sort()
return [row[-1] for row in results]
On Tue, 2003-05-13 at 08:23, Mark Nenadov wrote:
> Hello all,
>
> I have a simple ZCatalog query with a sort_on and sort_order being
> passed to it.
>
> Is there any way I can do the sort on multiple columns? This seems like
> an important feature. I've heard that is not possible, but I'm wondering
> if I am just missing something/getting wrong info.
>
> I'm already looking into the Generic Sort External Method, but I'm
> wondering if there is some other way to do this?
>
> Thanks,
> ~Mark
>
>
>
>
> _______________________________________________
> Zope maillist - Zope@zope.org
> http://mail.zope.org/mailman/listinfo/zope
> ** No cross posts or HTML encoding! **
> (Related lists -
> http://mail.zope.org/mailman/listinfo/zope-announce
> http://mail.zope.org/mailman/listinfo/zope-dev )
--
Michael Long <mlong@datalong.com>