title: Django: How to realise these relations?
body: <p>For an app, i have the following models:</p>
  
  <pre><code>Parent(models.Model):
      pass
  
  Child(models.Model):
      parent = models.ForeignKey(Parent)
  
  GrandChild(models.Model):
      child = models.ForeignKey(Child)
  </code></pre>
  
  <p>Each of this models can have an image (not shown in the code). In addition to this, each instance can be visible on the image of its parent or grand parent.
  For example, there can be a GrandChild A, which is visible on the related Child B or even on the Parent model C, which is the parent of B. I want to store in the database which instances are visible in wich image, also some additional information is needed, like the position where the instance is in the image. How is this possible with Django or what is the best way to realize this structure?</p>
  
  <p>These are the ideas i've thought of:</p>
  
  <p><strong>Implement the image as its own model with a ForeignKey to each of the possible classes:</strong> </p>
  
  <p>The visibility will be implemented as a many-to-many relation with a through model. So something like this:</p>
  
  <pre><code>Image(models.Model):
      image = ImageField()
      related_parent = models.ForeignKey(Parent)
      related_child = models.ForeignKey(Child)
      ....
  
  VisibleObject(models.Model):
      object = models.ForeignKey(Parent)
      image = models.ForeignKey(Image)
      # ... additional Fields
  </code></pre>
  
  <p>The problem with this approach are, according to me, that many of the ForeignKeys are never used and rather missleading. This approach seems to be unclean.</p>
  
  <p><strong>Implement the image as ContentType</strong></p>
  
  <p>So the Image from above would still be a class on its own, but instead of ForeignKeys, the ContetTypes Frameworke is used. This solution seems to be a lot cleaner but i don't know how to store the extra data for the relations.</p>
  
  <p><strong>Switch to NoSQL Database</strong></p>
  
  <p>This might also be a possibility. But as im not used to noSQL Databases, this would be the least prefered way. </p>
  
  <p><strong>to recap:</strong></p>
  
  <ul>
  <li>Each instance can have an image by it's own.</li>
  <li>Each instance can be visible on an image owned by it's parent or grandparent.</li>
  <li>The visibility should be stored with some extra date in the database</li>
  <li>At the moment, the extra data is allways the same, independet from the source class</li>
  </ul>