title: django model field definition for hierarchy, GenericForm
body: <p>I want to represent a model hierarchy of categories in django orm.
  So f.i. you could have categories such as:</p>
  
  <pre><code>TopCategory
      SubCategory1
          SubSubCategory
      SubCategory2
  </code></pre>
  
  <p>This is my field definition, which points to the parent category:</p>
  
  <pre><code>class Category(models.Model)
      parentcategory = models.OneToOneField('self', blank = True, null = True)
  </code></pre>
  
  <p>And I use a GenericForm in the view:</p>
  
  <pre><code>def detail(request, category_id):   
      categoryInstance = Category.objects.get(pk = category_id)   
      GenericForm = modelform_factory(Category)
      form = GenericForm(instance = categoryInstance)
  
      if request.method == 'POST':
          form = GenericForm(request.POST, instance = categoryInstance)
          if form.is_valid():
              form.save()
  </code></pre>
  
  <p>This does work, there is only one slight problem.
  No category should be allowed to point to itself as a parent.
  The form renders a dropdown where all categories are listed however.</p>
  
  <p>I did try something like this in the field definition:</p>
  
  <pre><code>limit_choices_to = Q('parentcategory_id' is not id)
  </code></pre>
  
  <p>But that gave me an error.
  I could probably check and present an error message to the user, but maybe someone knows another way?</p>