Ordering a Django queryset by the returned results of a method

Viewed 16790

Let's say I have a queryset of things Bill has worked on like this:

test=Things.objects.filter(user='Bill')

Now I want to sort all those things by the date they were assigned to bill. Unfortunately the assignment date isn't a field in the Thing model. Instead there's a method named thing_date() that figures it out and returns the date. For example, the following:

Thingobject.thing_date()

...returns the date. I guess what I want to do is something like:

test=Things.objects.filter(user='Bill').order_by(self__thing_date())

...but I know that won't work. Is there another way?

Update

Not surprisingly other folks have been down this road before. Link

2 Answers
Related