Ticket #1328: management_rename.diff
File management_rename.diff, 2.2 KB (added by , 19 years ago) |
---|
-
management.py
583 583 except NotImplementedError: 584 584 relations = {} 585 585 for i, row in enumerate(db.get_table_description(cursor, table_name)): 586 column_name = row[0] 586 field_name = column_name = row[0] 587 if field_name in ('and', 'assert', 'break', 'class', 'continue', 'def', 'elif', 'else', 'except', 'exec', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'not', 'or', 'pass', 'print', 'raise', 'return', 'try', 'while', 'yield'): 588 field_name = '%s_field'%(field_name) 589 587 590 if relations.has_key(i): 588 591 rel = relations[i] 589 592 rel_to = rel[1] == table_name and "'self'" or table2model(rel[1]) 590 593 if column_name.endswith('_id'): 591 594 field_desc = '%s = meta.ForeignKey(%s' % (column_name[:-3], rel_to) 592 595 else: 593 field_desc = '%s = meta.ForeignKey(%s, db_column=%r' % ( column_name, rel_to, column_name)596 field_desc = '%s = meta.ForeignKey(%s, db_column=%r' % (field_name, rel_to, column_name) 594 597 else: 595 598 try: 596 599 field_type = db.DATA_TYPES_REVERSE[row[1]] … … 607 610 else: 608 611 extra_params = {} 609 612 613 if field_name != column_name: 614 extra_params['db_column'] = '%r'%column_name 615 610 616 if field_type == 'CharField' and row[3]: 611 617 extra_params['maxlength'] = row[3] 612 618 613 field_desc = '%s = meta.%s(' % ( column_name, field_type)619 field_desc = '%s = meta.%s(' % (field_name, field_type) 614 620 field_desc += ', '.join(['%s=%s' % (k, v) for k, v in extra_params.items()]) 615 621 field_desc += ')' 622 623 if field_name != column_name: 624 field_desc += ' # Db field was Python reserved word - field renamed' 625 616 626 if field_type_was_guessed: 617 627 field_desc += ' # This is a guess!' 618 628 yield ' %s' % field_desc