django-multilingual-ng icon indicating copy to clipboard operation
django-multilingual-ng copied to clipboard

MultilingualModelQueryset order_by

Open gillesfabio opened this issue 15 years ago • 4 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.

gillesfabio avatar May 28 '10 10:05 gillesfabio

order_by is kinda buggy anyway, so any improvements to it are greatly appreciated

ojii avatar May 28 '10 11:05 ojii

I sent you a pull request of my branch. Hope it helps.

gillesfabio avatar May 28 '10 12:05 gillesfabio

Other solution - simple patch in query.py: after line 516 self._field_name_cache = None add self._default_language = get_default_language()

Alrond avatar Jun 16 '10 17:06 Alrond

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.

piotrkilczuk avatar Sep 15 '10 07:09 piotrkilczuk