title: Django models.py Circular Foreign Key
body: <p>I have a django app which basically is just a photo album. Right now I have two models: <code>Image</code> and <code>Album</code>. Among other things, each <code>Album</code> has a foreign key to an <code>Image</code> to be its thumbnail and each <code>Image</code> has a foreign key to the <code>Album</code> it belongs in. However, when I try to use <code>manage.py syncdb</code> or <code>manage.py sqlall</code> I get errors saying the class not defined first in models.py isn't defined when it is used in the first class defined.</p>
  
  <p>models.py (abridged):</p>
  
  <pre><code>from django.db import models
  import os
  
  class Album(models.Model):
      thumb = models.ForeignKey(Image, null=True, blank=True)
  
  class Image(models.Model):
      image = models.ImageField(upload_to='t_pics/images')
      thumb = models.ImageField(upload_to='t_pics/images/thumbs')
      album = models.ForeignKey(Album)
  </code></pre>
  
  <p>Error I get when I do <code>manage.py sqlall appname</code>:</p>
  
  <pre><code>[...]
   File "/path/to/file/appname/models.py", line 4, in ?
      class Album(models.Model):
    File "/path/to/file/appname/models.py", line 5, in Album
      thumb = models.ForeignKey(Image, null=True, blank=True)
  NameError: name 'Image' is not defined
  </code></pre>
  
  <p>I get the same error when I switch the order of the classes in models.py except it says <code>'Album' undefined</code> instead of <code>'Image' undefined</code> I also tried commenting the dependancy in the first class then uncommenting after everything else was successfully imported but that didn't help. How should I go about making this work? I'm reluctant to make an entire third class <code>Thumb</code> because it will have a lot of the same code as <code>Image</code> I'm also pretty sure I could manually add the foreign key to the database but I want this to be clean and not hackish.</p>