On 5 Feb, 21:21, Peter Herndon wrote:
> Never forget, Django is Python. One way to do what you need would be to
> implement the __cmp__ special method on your Computer class. Then, if you
> make e.g. a list out of the results of your QuerySet, you can call sort() on
> the list, and you're done.
>
> The downside is that you need to make a list of your QuerySet, which may
> require quite a bit of memory, depending on the number of objects returned.
>
> The reason you can't order_by something that's not in the database is that
> the order_by method is SQL and is executed in the database as part of the
> query. The reason you can't sort() a queryset is that it's a generator, not
> a list, so it only lazily instantiates your model objects.
>
Just the ticket. Many thanks Peter. I was doing a list comprehension
along the lines of
list = [ x for x in Computer.objects.all() ]
which seemed to work, but your __cmp__ method looks much nicer.
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.