Rob Slotboom wrote:
> in the model class:
>    def __cmp__(self, other):
>        return cmp(self.get_absolute_url, other.get_absolute_url)
> 
> In a function:
>    cat_list = []
>    for cat in Category.objects.all():
>       cat_list.append(cat)
>    cat_list.sort()

Hi Rob,

I think the problem is that get_absolute_url isn't actually being called so
you're sorting by the method itself instead of by the method result. So
just put () after get_absolute_url and it should work. Just a note though
that I'd write it like so:

sorted(Category.objects.all(), key=Category.get_absolute_url)

Then Python will call the method for you (and maybe cache the result for
further comparisons).

-- 
Brian Beck
Adventurer of the First Order


--~--~---------~--~----~------------~-------~--~----~
 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