Fix `.select_related(None)`
@@ -48,6 +48,7 @@ def get_translatable_fields_for_model(model):
def rewrite_lookup_key(model, lookup_key):
+ try:
pieces = lookup_key.split('__', 1)
original_key = pieces[0]
@@ -67,6 +68,8 @@ def rewrite_lookup_key(model, lookup_key):
transmodel = fields_to_trans_models[original_key]
pieces[1] = rewrite_lookup_key(transmodel, pieces[1])
return '__'.join(pieces)
+ except AttributeError:
+ return lookup_key
def append_fallback(model, fields):
@@ -121,10 +124,13 @@ def append_lookup_keys(model, fields):
def rewrite_order_lookup_key(model, lookup_key):
+ try:
if lookup_key.startswith('-'):
return '-' + rewrite_lookup_key(model, lookup_key[1:])
else:
return rewrite_lookup_key(model, lookup_key)
+ except AttributeError:
+ return lookup_key
_F2TM_CACHE = {}
@@ -351,11 +357,7 @@ class MultilingualQuerySet(models.query.QuerySet):
return super(MultilingualQuerySet, self).order_by(*field_names)
new_args = []
for key in field_names:
- try:
- new_arg = rewrite_order_lookup_key(self.model, key)
- except AttributeError:
- new_arg = key
- new_args.append(new_arg)
+ new_args.append(rewrite_order_lookup_key(self.model, key))
return super(MultilingualQuerySet, self).order_by(*new_args)
def update(self, **kwargs):
