On Nov 4, 7:02 pm, "Karen Tracey" <[EMAIL PROTECTED]> wrote:
> On 11/4/07, Brot <[EMAIL PROTECTED]> wrote:
>
>
>
> > > partner_list = [ep.partner for ep in Event.objects.latest
> > > ('date').eventpartner_set.all()]
>
> > Ok, that works! But there is another problem now. I would like to sort
> > the list of partners.
> > The sort-criteria should be a field from the partner model. e.g: name
> > Is this possible?
>
> Sure, check outhttp://wiki.python.org/moin/HowTo/Sortingfor lots of
> examples on how to sort. I think either
>
> partner_list.sort(lambda x,y: cmp(x.name, y.name))
>
> or (if using Python 2.4 or higher)
>
> import operator
> partner_list.sort(key=operator.attrgetter('name'))
>
> would do what you're looking for.
>
> Karen
Ok, thank you... that's standard python stuff. It's no secret, that
I'm new to python :-(
But I found another solution. I don't really now which on is the
better one?!
partnerlist = [ep.partner for ep in
Event.objects.latest('date').eventpartner_set.all().select_related().order_by('hp_partner.name')]
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---