title: Django create a dict with values of a model field as key and model instance as value
body: <p>I have a model <code>Quest</code> and it has a field <code>type</code>. I want to have a dict that maps <code>type</code> to a list of <code>Quest</code>. My current way of doing it is just iterating over all the <code>Quest</code> objects and append them to the list.</p>
  
  <pre><code>from collections import defaultdict
  
  quests = Quest.objects.all()
  dictionary = defaultdict(list)
  for quest in quests:
      dictionary[quest.type].append(quest)
  </code></pre>
  
  <p>I am wondering if Django <code>QuerySet</code> has a better way to do it. I looked up <code>aggregation()</code>, <code>value_list()</code> and <code>values()</code> but they don't seem to achieve what I want to do.</p>