Thank you! On 15 Dez., 15:21, Daniel Roseman <dan...@roseman.org.uk> wrote: > On Wednesday, December 15, 2010 1:34:15 PM UTC, josch wrote: > > > Hallo, > > > I know, that the normal way to do that is to write the return value of > > the method to the foreign model, always when a model that affects the > > return value changes, and than order by that value of the model. > > > But I have a model whoose objects gets a specific state after they are > > older than a specific number of days. And i don`t want to use a > > cronjob or something like that to update the foreign model`s value. > > > So, can someone tell me, how I can order a query set by one of the > > function of it`s models, in a pinch by reordering the obecjts in a new > > object array or some kind like that. > > > There are not a lot of records I have to order, so I think there is no > > performance problem for my kind of application. > > > Thank you! > > You can convert the queryset to a list, then call the standard list sort > method on it, passing the method as the key: > > results = MyModel.objects.filter(criteria=whatever) > results = list(results) > results.sort(key=lambda x: x.my_method()) > > Obviously, as you note, this is not as efficient as doing the sorting in the > database, but for small numbers of objects it should be acceptable. > -- > DR.
-- 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.