On Feb 2, 10:07 am, Łukasz Rekucki <lreku...@gmail.com> wrote: > Just came to my mind, that we could just mimic the DBs and have a > Collate operator (like Q, F, Count, etc.) + maybe some defaults on the > model: > > M.objects.order_by(Collate("name", "uca")) > M.objects.filter(name__gte=Collate('e', "fi"))
I have been thining a lot about allowing annotate and order_by to accept basically anything that has an .as_sql() method. So that you could do things like: qs.annotate(name_upper=RawSQL("upper(%s)", params=f('name')).order_by('name_upper') of course, the above example is doable using current Django ORM. or maybe: qs.annotate(name_upper=RawSQL("upper(%s)", params=f('name')).order_by(RawSQL('%s collate "%%s" desc nulls last', params=(f('name_upper'), 'fi-FI')) These would be much better than the .extra(), as aliases are relabled properly and you can "chain" the RawSQL clauses. In the ORM the code that deals with .extra handling is kinda hacky, and this would probably make that part of the ORM cleaner. I think those really are doable. Using objects in cols, order by etc. inside the ORM instead of the current implementation would probably make the ORM cleaner and faster. Of course, without patch this is easy to claim... Problem is, I don't have time to do anything about this right now, and it seems the ORM-knowing core developers have the same problem. - Anssi -- You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@googlegroups.com. To unsubscribe from this group, send email to django-developers+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-developers?hl=en.