title: Django - Add field to queryset to store computation results
body: <p>I'm pretty new to Django and come from the PHP world. I'm trying to 'add' a field to a queryset after computing things, and don't know how to do it. In PHP I would just add a column in an array and store my stuff in it. </p>
  
  <p>Here's my code: </p>
  
  <pre><code>def (id):
      mystuff_details    = mystuff_details.objects.filter(stuff_id=id)
      newthing = '';
      for mystuff in mystuff_details:
          newthing_lists = //some query to get another queryset
          for newthing_list in newthing_lists:
              newthing = newthing_list.stuffIwant
              //Here I want to make some computation, and ADD something to newthing, let's say:  
              to_add = (mystuff.score+somethingelse)
              //I've heard about the .append but I'm sure I'm screwing it up
              newthing.append(to_add)
  </code></pre>
  
  <p>So basically in my template I'd like to be able to call:
      {% for newthing in newthings_list %}
         {{ newthing.to_add }}
      {% end %}</p>
  
  <p><strong>TL;DR:</strong> I basically want to retrieve a list of stuff from my database, and in this list of objects ADD a field that will contain a computed value. </p>
  
  <p>Let me know if it's unclear, I'm having a hard time switching from php to django haha. </p>
  
  <p>Thanks!</p>
  
  <p>EDIT: </p>
  
  <p>So, I'm trying with a dictionnary, but I must be missing the logic: </p>
  
  <pre><code>def (id):
      mystuff_details    = mystuff_details.objects.filter(stuff_id=id)
      newthing = {};
      for mystuff in mystuff_details:
          newthing_lists = //some query to get another queryset
          for newthing_list in newthing_lists:
              //Newthing_list can have several times the same I, and the scores need to add up
              if newthing[newthing_list.id] &gt; 0: //This doesn't seem to work and throws an error (KeyError)
                  newthing[newthing_list.id] = newthing[newthing_list.id] + some_calculated_thing
              else: 
                  newthing[newthing_list.id] = some_calculated_thing
  </code></pre>
  
  <p>And then when I'll get that working, I don't know how to access it in the template:</p>
  
  <pre><code> {% for id in my_list %}
       {{newthing[id]}} ? Or something like newthing.id ?
   {% end %}
  </code></pre>
  
  <p>Thanks!</p>