> Can I order_by a function within the model? I know you can list them > in the admin inteface, etc. But can you order_by a model function? Or > would you have to write a custom piece of code to do that?
In addition to the two solutions that John mentioned, you can do the following in many cases: Precompute the value of the model function and save it into a column of your model. Then use the normal Django DB API to order by that column etc. You could compute and save this function's value from within an overridden model.save() method. The advantage of this approach is that you only compute the function when a model instance is saved or updated. So it should work better than the Python list sort approach in cases where you have a large number of records to go through *and* where that function involves resource intensive calculations that you don't really want to perform every time the instance is accessed. Obviously, this doesn't work if the function's value changes based on factors external to the model's own fields. -Rajesh D --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---