title: Django: list all reverse relations of a model
body: <p>I would like my django application to serve a list of any model's fields (this will help the GUI build itself).</p>
  
  <p>Imagine the classes (ignore the fact that all field of <code>Steps</code> could be in <code>Item</code>, I have my reasons :-) )</p>
  
  <pre><code>class Item(models.Model):
      name = models.CharField(max_length=100)
      description = models.TextField()
  
  class Steps(models.Model):
      item = models.OneToOneField('Item', related_name='steps')
      design = models.BooleanField(default=False)
      prototype = models.BooleanField(default=False)
      production = models.BooleanField(default=False)
  </code></pre>
  
  <p>Now, when I want to list a model's fields:</p>
  
  <pre><code>def get_fields(model):
      return model._meta.fields + model._meta.many_to_many
  </code></pre>
  
  <p>But I would also like to get the list of "related" one-to-one foreign keys to my models. In my case <code>Item.steps</code> would not be in that list.</p>
  
  <p>I have found that <code>model._meta.get_all_field_names</code> does include all the related fields. </p>
  
  <p>But when I call <code>Item._meta.get_field_by_name('steps')</code> it returns a tuple holding a <code>RelatedObject</code>, which does not tell me instantly whether this is a <em>single</em> relation or a one-to-many (I want to list only reversed one-to-one relations).</p>
  
  <p>Also, I can use this bit of code:</p>
  
  <pre><code>from django.db.models.fields.related import SingleRelatedObjectDescriptor
  reversed_f_keys = [attr for attr in Item.__dict__.values() \
                    if isinstance(attr, SingleRelatedObjectDescriptor)]
  </code></pre>
  
  <p>But I'm not very satisfied with this.</p>
  
  <p>Any help, idea, tips are welcome!</p>
  
  <p>Cheers</p>