q = list(a) + list(b) + list(c)
q.sort('-date')

The problem you have here is the q.sort() method doesn't understand
how to compare your objects. '-date' means nothing to it.    I'm
pretty sure you need to write your own comparison function and pass
that to sort.  If you've got models with the same field name to sort
by, you can use operator:

import operator
sorted_list=sorted(q,key=operator.attrgetter('modified'))

If you've got to inspect the object and 'guess' the date sort field,
or have different field names to use, I think the only way to do it is
with your own comparison function.

def cmp_date_field(x,y):
   # do some model inspection to find attribute name to use for date
comparison
   xdate=getattr(x,datefield_x,None)
   ydate=getattr(y,datefield_y,None)
   if xdate> ydate: return 1
   elif xdate==ydate: return 0
   else: return -1

q.sort(cmp_date_field)



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to