MultilingualModelQueryset order_by
gillesfabio opened this issue · comments
Hello,
I spot some bugs with MultilingualModelQueryset
and order_by
method.
- Create a model with a
DateTimeField
- In the administration class, add
date_hierarchy
for this field - Add some fixtures created the same date
- See the results: in the date hierarchy, year appears more than once
There's a SELECT
and an ORDER_BY
on the model id
. It's probably the extra
method returned.
Other bug:
- Enter in the shell
- Try to order by on a translated field (example:
Page.objects.order_by('title')
) - It fails: language is None
Probably:
getattr(self, '_default_language', None)
Could be fixed with:
getattr(self, '_default_language', get_default_language())
I forked the project and created a dedicated branch with my fixes:
http://github.com/gillesfabio/django-multilingual-ng/tree/orderby-issue
It's probably not the correct fix but it works "well" on my small projects. I didn't test it on large ones.
Hope it helps.
Thanks for your great job.
order_by is kinda buggy anyway, so any improvements to it are greatly appreciated
I sent you a pull request of my branch.
Hope it helps.
Other solution - simple patch in query.py:
after line 516
self._field_name_cache = None
add
self._default_language = get_default_language()
AWESOME Alrond, it works :) I'll commit that to my fork.
Exception is still raised if you define ordering in the admin class, though. I'll take a look into that.