예제 #1
0
 def get_sync_sql(self, field_name, missing_langs, model):
     """ returns SQL needed for sync schema for a new translatable field """
     qn = connection.ops.quote_name
     style = no_style()
     sql_output = []
     db_table = model._meta.db_table
     # Retrieve the actual database column name, since it is different to field_name for a ForeignKey:
     exec('column = model.%s.__doc__' % field_name)
     was_translatable_before = self.was_translatable_before(
         column, db_table)
     for lang in missing_langs:
         new_field = get_real_fieldname(field_name, lang)
         f = model._meta.get_field(new_field)
         col_type = f.db_type()
         field_sql = [
             style.SQL_FIELD(qn(f.column)),
             style.SQL_COLTYPE(col_type)
         ]
         # column creation
         sql_output.append("ALTER TABLE %s ADD COLUMN %s" %
                           (qn(db_table), ' '.join(field_sql)))
         if lang == self.default_lang and not was_translatable_before:
             # data copy from old field (only for default language)
             sql_output.append("UPDATE %s SET %s = %s" % (qn(db_table), \
                               qn(f.column), qn(column)))#qn(field_name)))
         if not f.null and lang == self.default_lang:
             # changing to NOT NULL after having data copied
             sql_output.append("ALTER TABLE %s ALTER COLUMN %s SET %s" % \
                               (qn(db_table), qn(f.column), \
                               style.SQL_KEYWORD('NOT NULL')))
     if not was_translatable_before:
         # we drop field only if field was no translatable before
         sql_output.append("ALTER TABLE %s DROP COLUMN %s" %
                           (qn(db_table), qn(column)))  #qn(field_name)))
     return sql_output
예제 #2
0
 def get_sync_sql(self, field_name, missing_langs, model):
     """ returns SQL needed for sync schema for a new translatable field """
     qn = connection.ops.quote_name
     style = no_style()
     sql_output = []
     db_table = model._meta.db_table
     # Retrieve the actual database column name, since it is different to field_name for a ForeignKey:
     exec('column = model.%s.__doc__' % field_name)
     was_translatable_before = self.was_translatable_before(column, db_table)
     for lang in missing_langs:
         new_field = get_real_fieldname(field_name, lang)
         f = model._meta.get_field(new_field)
         col_type = f.db_type()
         field_sql = [style.SQL_FIELD(qn(f.column)), style.SQL_COLTYPE(col_type)]
         # column creation
         sql_output.append("ALTER TABLE %s ADD COLUMN %s" % (qn(db_table), ' '.join(field_sql)))
         if lang == self.default_lang and not was_translatable_before:
             # data copy from old field (only for default language)
             sql_output.append("UPDATE %s SET %s = %s" % (qn(db_table), \
                               qn(f.column), qn(column)))#qn(field_name)))
         if not f.null and lang == self.default_lang:
             # changing to NOT NULL after having data copied
             sql_output.append("ALTER TABLE %s ALTER COLUMN %s SET %s" % \
                               (qn(db_table), qn(f.column), \
                               style.SQL_KEYWORD('NOT NULL')))
     if not was_translatable_before:
         # we drop field only if field was no translatable before
         sql_output.append("ALTER TABLE %s DROP COLUMN %s" % (qn(db_table), qn(column)))#qn(field_name)))
     return sql_output
예제 #3
0
def get_real_columnname(field, model, lang=None):
    if lang is None:
        lang = get_language()
    field_name = get_real_fieldname(field, lang)
    f = model._meta.get_field(field_name)
    return f.column
예제 #4
0
def get_real_columnname(field, model, lang=None):
    if lang is None:
       lang = get_language()
    field_name = get_real_fieldname(field, lang)
    f = model._meta.get_field(field_name)
    return f.column