order_by with translation and empty fields

27 views
Skip to first unread message

Tim Schneider

unread,
Nov 23, 2015, 7:07:41 AM11/23/15
to django-modeltranslation
Hi,

I recently started out using django-modeltranslation and am quite pleased with how easy it has been to use and integrate so far.

As of now, I only have two languages I want to use, namely german (default) and english.
I have a couple of django-tables2 tables in my application which supports the sorting by columns. As the documentation states, the order_by uses the correct column based on the current language nicely.
I now however have the problem, that not all my model instances have an english translation resulting in some of the english column fields to be NULL. In such a case the accessor is, of course, overwritten by modeltranslation to display the german name which is fine. The ordering in such a case is, however, still based on the values in the english field, resulting in a non alphabetic ordering for the fields with no english translation.

Is this a known problem? Are there any fixes apart from specifying each english translation?
Is it possible to tell the MultilingualManager to use something like
ORDER BY COALESCE(name_en, name_de)

instead of simply using
ORDER BY name_en

?

Thank you for your help.
Reply all
Reply to author
Forward
0 new messages