title: Filling a complex object from database in Django
body: <p>I am trying to figure out how I can create a complex object in Django, using data retrieved from different, joined tables in a database, without having to do a series of explicit queries and then manually putting it all together.</p>
  <p>Lets say I have three tables that look like this</p>
  <pre><code>**parent**
   - id
   - name
  
  **attribute**
  - id
  - parent_id *(ForeignKey)*
  - name
  - value
  
  
  **modifier**
  - attribute_id *(ForeignKey)*
  - value
  - duration
  </code></pre>
  <p>So, every parent has an arbitrary number of attributes, and each attribute can have an arbitrary number of modifiers, each identified with ForeignKeys in their respective models.</p>
  <p>From entries in these tables, I would like to build a Python object that has the following structure</p>
  <pre><code>**object**
  - id
  - name
  - attributes {} 
      - name :  (value, modifiers[(value, duration), (value, duration), …])
      - name :  (value, modifiers[(value, duration), (value, duration), …])
      - …
  </code></pre>
  <p>What is the best and most efficient approach to achieving something like this in Django? Is there even a way or will I have to run multiple queries and fill the object in discrete steps?</p>