On Nov 7, 1:54 pm, Thomas Guettler <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I just discovered, that you can't sort a list of model instances.
>
> This failed with AssertionError:
>
>         view_groups=sorted([brg.group for brg in ... ])
>         change_groups=sorted([...])
>         if view_groups==change_groups:
>             ...
>         else:
>             assert set(view_groups)!=set(change_groups), (view_groups,
> change_groups)
>
> Is there a reason why this is this way?
>
>    Thomas
>
> --
> Thomas Guettler,http://www.thomas-guettler.de/
> E-Mail: guettli (*) thomas-guettler + de

You haven't given any key or cmp values in the sorted() call to tell
it what to sort on. Certainly this works for me:
sorted([item for item in qs], key=lambda x: x.name)

Although I would have to wonder why you're doing it this way, rather
than using the database to sort them? I understand that you're getting
all group items that are related to a brg, but a better way of doing
it would be something like:
Group.objects.filter(brg__isnull=False).order_by('name')
or whatever.

--
DR.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
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