diff --git a/django/core/management/commands/inspectdb.py b/django/core/management/commands/inspectdb.py
index e45f22c..2db7a85 100644
a
|
b
|
class Command(NoArgsCommand):
|
41 | 41 | yield '' |
42 | 42 | yield 'from %s import models' % self.db_module |
43 | 43 | yield '' |
| 44 | known_models = [] |
44 | 45 | for table_name in connection.introspection.get_table_list(cursor): |
45 | 46 | yield 'class %s(models.Model):' % table2model(table_name) |
| 47 | known_models.append(table2model(table_name)) |
46 | 48 | try: |
47 | 49 | relations = connection.introspection.get_relations(cursor, table_name) |
48 | 50 | except NotImplementedError: |
… |
… |
class Command(NoArgsCommand):
|
77 | 79 | |
78 | 80 | if i in relations: |
79 | 81 | rel_to = relations[i][1] == table_name and "'self'" or table2model(relations[i][1]) |
80 | | field_type = 'ForeignKey(%s' % rel_to |
| 82 | |
| 83 | if rel_to in known_models: |
| 84 | field_type = 'ForeignKey(%s' % rel_to |
| 85 | else: |
| 86 | field_type = "ForeignKey('%s'" % rel_to |
| 87 | |
81 | 88 | if att_name.endswith('_id'): |
82 | 89 | att_name = att_name[:-3] |
83 | 90 | else: |