Exemplo n.º 1
0
 def order_by(self, *field_names):
     if hasattr(self.model._meta, 'translation_model'):
         trans_opts = self.model._meta.translation_model._meta
         new_field_names = []
         for field_name in field_names:
             prefix = ''
             if field_name[0] == '-':
                 prefix = '-'
                 field_name = field_name[1:]
             field_and_lang = trans_opts.translated_fields.get(field_name)
             if field_and_lang:
                 field, language_code = field_and_lang
                 if language_code is None:
                     language_code = getattr(self, '_default_language',
                                             None)
                 real_name = get_translated_field_alias(
                     field.attname, language_code)
                 new_field_names.append(prefix + real_name)
             else:
                 new_field_names.append(prefix + field_name)
         return super(MultilingualModelQuerySet,
                      self).extra(order_by=new_field_names)
     else:
         return super(MultilingualModelQuerySet,
                      self).order_by(*field_names)
Exemplo n.º 2
0
 def __init__(self, model, connection, where=WhereNode):
     self.extra_join = {}
     extra_select = {}
     super(MultilingualQuery, self).__init__(model, connection, where=where)
     opts = self.model._meta
     qn = self.quote_name_unless_alias
     qn2 = self.connection.ops.quote_name
     master_table_name = opts.db_table
     translation_opts = opts.translation_model._meta
     trans_table_name = translation_opts.db_table
     if hasattr(opts, 'translation_model'):
         master_table_name = opts.db_table
         for language_id in get_language_id_list():
             for fname in [f.attname for f in translation_opts.fields]:
                 table_alias = get_translation_table_alias(trans_table_name,
                     language_id)
                 field_alias = get_translated_field_alias(fname,
                     language_id)
                 extra_select[field_alias] = qn2(table_alias) + '.' + qn2(fname)
         self.add_extra(extra_select, None,None,None,None,None)
Exemplo n.º 3
0
 def order_by(self, *field_names):
     if hasattr(self.model._meta, 'translation_model'):
         trans_opts = self.model._meta.translation_model._meta
         new_field_names = []
         for field_name in field_names:
             prefix = ''
             if field_name[0] == '-':
                 prefix = '-'
                 field_name = field_name[1:]
             field_and_lang = trans_opts.translated_fields.get(field_name)
             if field_and_lang:
                 field, language_code = field_and_lang
                 if language_code is None:
                     language_code = getattr(self, '_default_language', None)
                 real_name = get_translated_field_alias(field.attname,
                                                        language_code)
                 new_field_names.append(prefix + real_name)
             else:
                 new_field_names.append(prefix + field_name)
         return super(MultilingualModelQuerySet, self).extra(order_by=new_field_names)
     else:
         return super(MultilingualModelQuerySet, self).order_by(*field_names)
Exemplo n.º 4
0
 def __init__(self, model, where=WhereNode):
     self.extra_join = {}
     self.include_translation_data = True
     extra_select = {}
     super(MultilingualQuery, self).__init__(model, where=where)
     opts = self.model._meta
     qn = self.get_compiler(DEFAULT_DB_ALIAS).quote_name_unless_alias
     qn2 = self.get_compiler(DEFAULT_DB_ALIAS).connection.ops.quote_name
     master_table_name = opts.db_table
     translation_opts = opts.translation_model._meta
     trans_table_name = translation_opts.db_table
     if hasattr(opts, 'translation_model'):
         master_table_name = opts.db_table
         for language_code in get_language_code_list():
             for fname in [f.attname for f in translation_opts.fields]:
                 table_alias = get_translation_table_alias(trans_table_name,
                     language_code)
                 field_alias = get_translated_field_alias(fname,
                     language_code)
                 extra_select[field_alias] = qn2(table_alias) + '.' + qn2(fname)
         self.add_extra(extra_select, None, None, None, None, None)
         self._trans_extra_select_count = len(self.extra_select)
Exemplo n.º 5
0
 def __init__(self, model, connection, where=WhereNode):
     self.extra_join = {}
     self.include_translation_data = True
     extra_select = {}
     super(MultilingualQuery, self).__init__(model, connection, where=where)
     opts = self.model._meta
     qn = self.quote_name_unless_alias
     qn2 = self.connection.ops.quote_name
     master_table_name = opts.db_table
     translation_opts = opts.translation_model._meta
     trans_table_name = translation_opts.db_table
     if hasattr(opts, 'translation_model'):
         master_table_name = opts.db_table
         for language_id in get_language_id_list():
             for fname in [f.attname for f in translation_opts.fields]:
                 table_alias = get_translation_table_alias(
                     trans_table_name, language_id)
                 field_alias = get_translated_field_alias(
                     fname, language_id)
                 extra_select[field_alias] = qn2(table_alias) + '.' + qn2(
                     fname)
         self.add_extra(extra_select, None, None, None, None, None)
         self._trans_extra_select_count = len(self.extra_select)