title: django-contenttypes - List All Generic Relations for Model
body: <p>I would like to reflect on a model and list all its backward generic relations.</p>
  
  <p>My model looks like this:</p>
  
  <pre><code>class Service(models.Model):
      host = models.ForeignKey(Host)
  
      statuses = generic.GenericRelation(Status)
  </code></pre>
  
  <p>The Status object looks like this:</p>
  
  <pre><code>class Status(TrackedModel):
      content_type = models.ForeignKey(ContentType)
      object_id = models.PositiveIntegerField()
      content_object = generic.GenericForeignKey()
  
      class Meta:
          verbose_name_plural = 'statuses'
  </code></pre>
  
  <p>I would like to programatically learn that <code>statuses</code> is a generic relation for the Service model. Is this possible? <code>Status._meta.fields</code> does not show <code>statuses</code>, but <code>Status._meta.get_all_field_names()</code> does, only it shows other unwanted things too.</p>
  
  <p>I thought that this might be a possible solution, but it seems really messy to me. I'd love to hear of a better one.</p>
  
  <pre><code>from django.db.models.fields import FieldDoesNotExist
  from django.contrib.contenttypes import generic
  
  generic_relations = []
  for field_name in Service._meta.get_all_field_names():
      try:
          field = Service._meta.get_field(field_name)
      except FieldDoesNotExist:
          continue
  
      if isinstance(field, generic.GenericRelation):
          generic_relations.append(field)
  </code></pre>
  
  <p>Thank you!</p>