title: get_or_create generic relations in Django & python debugging in general
body: <p>I ran the code to create the generically related objects from this demo:
  <a href="http://www.djangoproject.com/documentation/models/generic_relations/" rel="noreferrer">http://www.djangoproject.com/documentation/models/generic_relations/</a></p>
  
  <p>Everything is good intially:</p>
  
  <pre><code>&gt;&gt;&gt; bacon.tags.create(tag="fatty")
  &lt;TaggedItem: fatty&gt;
  &gt;&gt;&gt; tag, newtag = bacon.tags.get_or_create(tag="fatty")
  &gt;&gt;&gt; tag
  &lt;TaggedItem: fatty&gt;
  &gt;&gt;&gt; newtag
  False
  </code></pre>
  
  <p>But then the use case that I'm interested in for my app:</p>
  
  <pre><code>&gt;&gt;&gt; tag, newtag = bacon.tags.get_or_create(tag="wholesome")
  Traceback (most recent call last):
    File "&lt;console&gt;", line 1, in &lt;module&gt;
    File "/usr/local/lib/python2.6/dist-packages/django/db/models/manager.py", line 123, in get_or_create
      return self.get_query_set().get_or_create(**kwargs)
    File "/usr/local/lib/python2.6/dist-packages/django/db/models/query.py", line 343, in get_or_create
      raise e
  IntegrityError: app_taggeditem.content_type_id may not be NULL
  </code></pre>
  
  <p>I tried a bunch of random things after looking at other code:</p>
  
  <pre><code>&gt;&gt;&gt; tag, newtag = bacon.tags.get_or_create(tag="wholesome", content_type=TaggedItem)
  ValueError: Cannot assign "&lt;class 'generics.app.models.TaggedItem'&gt;": "TaggedItem.content_type" must be a "ContentType" instance.
  </code></pre>
  
  <p>or:</p>
  
  <pre><code>&gt;&gt;&gt; tag, newtag = bacon.tags.get_or_create(tag="wholesome", content_type=TaggedItem.content_type)
  InterfaceError: Error binding parameter 3 - probably unsupported type.
  </code></pre>
  
  <p>etc.</p>
  
  <p>I'm sure somebody can give me the correct syntax, but the real problem here is that I have no idea what is going on.  I have developed in strongly typed languages for over ten years (x86 assembly, C++ and C#) but am new to Python.  I find it really difficult to follow what is going on in Python when things like this break.  </p>
  
  <p>In the languages I mentioned previously it's fairly straightforward to figure things like this out -- check the method signature and check your parameters.  Looking at the Django documentation for half an hour left me just as lost.  Looking at the source for get_or_create(self, **kwargs) didn't help either since there is no method signature and the code appears very generic.  A next step would be to debug the method and try to figure out what is happening, but this seems a bit extreme...</p>
  
  <p>I seem to be missing some fundamental operating principle here... what is it?  How do I resolve issues like this on my own in the future?</p>