If a class is defined after it is being referenced, you can just modify the code to reference the class name with quotes around it and it should alleviate any errors.
class Table1(models.Model): table1_id = models.AutoField(primary_key=True) table2 = models.ForeignKey('Table2') # notice the quotes around the name class Table2(models.Model): table2_id = models.AutoField(primary_key=True) On May 30, 4:24 pm, Vidja <[EMAIL PROTECTED]> wrote: > I'm using manage inspectdb to get an initial list of models for my > database. The only thing is that I'm spending a lot of time sorting > the models (>300) in such a way that each class is in the right order > regarding the foreign key dependencies. (making sure each model that > points to another is below its parent) > > Is there a method to automatically 'sort' the models, making sure the > base classes are above the depending classes? > > btw, i'm using postgres 8.1.11 and psycopg2 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---