title: Trees with Django models - different approaches
body: <p>I'm trying to make a simple tree app that accepts a user's input and adds nodes to a tree structure based on the input.  I want every node of the tree to be an instance of a general model, called nodes.</p>
  
  <p>An entry has up to two parts: a parent, which is the beginning of the string up to the first parentheses, and a child, which is in parentheses.</p>
  
  <p>For example, let's say a user enters the following:</p>
  
  <pre><code>"animal(cat)"
  "animal(dog)"
  "dog(golden retriever)"
  "organic_life_form(animal)"
  </code></pre>
  
  <p>This should generate a tree of this structure:</p>
  
  <pre><code>organic_life_form
          |
       animal
     /         \
  dog            cat
    |
  golden retriever
  </code></pre>
  
  <p>I made a mistake defining my 'node' model, but I'm not sure how to fix it.  </p>
  
  <pre><code>class Node(models.Model):
      name = models.CharField(max_length=200)
      parent = models.ForeignKey(Node)
      nodes = models.IntegerField(default=0)
  
      def __unicode__(self):
          return self.name 
  </code></pre>
  
  <p>Apparently I am not allowed to use another node as my foreign key "parent", as "Node" isn't yet defined.  This seems like a pretty basic error, but I still don't understand why one isn't allowed to do this. </p>
  
  <p>Can anyone explain why I am unable to use another "Node" as a foreign key?  And if it's a lost cause, what might be a better way of defining the type of structure I want?</p>