Django/python querysets - adding another "child" queryset as an item to each list object?
===

Apologies if the answer to this is obvious - I'm very new to django/python & haven't been able to find a solution in my searching so far.

I have a straightforward queryset, eg

    members = LibraryMembers.objects.all()

with this I can do:-

    for m in members:
      member_books = LibraryBorrows.objects.filter(member_id=m[u'id'])

What I really want though is to be able to serialize the results into json, so it looks something like this:-

    {
      "members":
      [
        {
          "id" : "1",
          "name" : "Joe Bloggs"
          "books":
          [
            {
              "name" : "Five Go Exploring",
              "author" : "Enid Blyton",
            },
            {
              "name" : "Princess of Mars",
              "author" : "Edgar Rice Burroughs",
            },
          ]
        }
      ]
    }

To my mind, the obvious thing to try was:-

    for m in members:
      m[u'books'] = LibraryBorrows.objects.filter(member_id=m[u'id'])

However I'm getting TypeError: 'LibraryBorrows' object does not support item assignment

Is there any way to achieve what I'm after?
  