tags:

views:

23

answers:

1

Trying to copy a Django model with ManyToManyField.

the model is

class Book(models.Model):
    cats = models.ManyToManyField(Category)

the view:

for book in books:
    book.name = "New Name"
    messageinfo = message.save()

    msg = Book(title=book.title, subject=book.subject)
    msg.save()

sort of works till here, makes a copy of book

the following gets an error

    for cat in book.cats:
            info = Category.objects.get(id=cat.id)
            msg.cats.add(info)

Error it produces

    TypeError at /
    'ManyRelatedManager' object is not iterable
+1  A: 
book.cats.all()

Example usage and docs.

rebus