title: Check if a OneToOne relation exists in Django
body: <p>Now I'm using django 1.6</p>
  
  <p>I have two models relates with a <code>OneToOneField</code>.</p>
  
  <pre><code>class A(models.Model):
      pass
  
  class B(models.Model):
      ref_a = models.OneToOneField(related_name='ref_b', null=True)
  </code></pre>
  
  <hr>
  
  <p>First see my code that points out the problem:</p>
  
  <pre><code>a1 = A.objects.create()
  a2 = A.objects.create()
  b1 = B.objects.create()
  b2 = B.objects.create(ref_a=a2)
  
  # then I call:
  print(a1.ref_b)  # DoesNotExist Exception raised
  print(a2.ref_b)  # returns b2
  print(b1.ref_a)  # returns None
  print(b2.ref_a)  # returns a2
  </code></pre>
  
  <p>Now the problem is, if I want to check a <code>A</code> object, to judge whether it exists a <code>B</code> objects referencing it. How can I do?</p>
  
  <p>The valid way I tried is only to try and catch an exception, but is there any other prettier way?</p>
  
  <hr>
  
  <p>My effort:</p>
  
  <p>1 - The below code works, but is too ugly!</p>
  
  <pre><code>b = None
  try:
      b = a.ref_b
  except:
      pass
  </code></pre>
  
  <p>2 - I also tried to check the attributes in a, but not working:</p>
  
  <pre><code>b = a.ref_b if hasattr(a, 'ref_b') else None
  </code></pre>
  
  <hr>
  
  <p>Do you meet the same problem, friends? Please point me a way, thank you!</p>