title: Django: Check if foreign key attribute is set
body: <p>I have the following model:</p>
  
  <pre><code>class A(models.Model):
      name = models.CharField(max_length=50)
      content_type = models.ForeignKey(ContentType)
  </code></pre>
  
  <p>This model is supposed to be the root model in some inheritance tree and content_type attribute is a kind of a hint about what type is really stored.
  Obviously, I should calculate <code>content_type</code> transparently upon A instance creation. I think, in <code>__init__</code>. But there is a problem - there are two main contexts in which A instances are created:</p>
  
  <ol>
  <li><code>a = A(name='asdfdf') # here we must fill in content_type</code></li>
  <li>by <code>QuerySet</code> machinery with <code>*args</code> tuple. In this case I shouldn't fill in <code>content_type</code></li>
  </ol>
  
  <p>So, I'm trying to write:</p>
  
  <pre><code>def __init__(self, *args, **kwargs):
      super(A, self).__init__(*args, **kwargs)
      if self.content_type is None: # &lt;&lt; here is the problem
          self.content_type = ContentType.objects.get_for_model(self)
  </code></pre>
  
  <p>The thing is <code>self.content_type</code> is <code>ReverseSingleRelatedObjectDescriptor</code> instance with <code>__get__</code> overriden so that it throws in case value is not set. Yes, I can do following:</p>
  
  <pre><code>def __init__(self, *args, **kwargs):
      super(A, self).__init__(*args, **kwargs)
      try: 
          self.content_type
      except Exception, v:
          self.content_type = ContentType.objects.get_for_model(self)
  </code></pre>
  
  <p>But I don't like it. Is there a more 'polite' way to check if the <code>ForeignKey</code> attribute is set?</p>