-
Notifications
You must be signed in to change notification settings - Fork 258
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Translated model SelectField not sorted in the correct language #600
Comments
Hi @EParisot, did you find a solution to this issue? |
Nop, we decided it was not vital but the problem is still there... |
@antoiloui in fact I just came accross it today, and fixed it by sorting the select options on the client side.
|
Amazing, thanks for sharing your solution @EParisot! |
For future reference, one way to do this server-side is to https://gist.github.com/LeMinaw/cdc9c92113f5d5a0af067c5846e90f32 |
@LeMinaw thank you for showing how it can be done. Does it mean that using For example all the entries have a value for english (default language), but not all have a french translation. Is it possible to get a correct ordering for french, i.e. the ordering is based on french and if not available, it defaults to english? If I understood correctly, this is what your code achieves, but I'm confused as why it wouldn't be the default behaviour. |
Yes, what you describe is roughly what the above code does. To me modeltranslation not ordering querysets this way by default sound reasonable: ordering and querysets annotations have a performance cost, and it is clearly stated in the docs that the status of original translated fields is unspecified. Now one can discuss if the library should provide a way to perform this kind of ordering through the translated model manager. |
Hi, I have a Select with objects that are countries, so model is called Country with a "name" and "code" attributes.
Names are perfectly translated but their order in a select box rendered from a model form, sorted alphabetically in english (default language), whatever I select in languages (except english of course)...
Code from models.py :
Code from translations.py
Code from forms.py
The text was updated successfully, but these errors were encountered: