I get an AttributeError: 'list' object has no attribute 'model'

Is there a way to circumvent this, or should I try to do something
involving a generic relationship for the models (i.e., a model with
almost nothing to it, to which all the other models have a generic
relationship)? Will that kind of thing work? (At this point, I can't
seem to wrap my head around generic relationships, which is why I
wanted to explore other options.

On Aug 22, 4:23 pm, Doug B <[EMAIL PROTECTED]> wrote:
> 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