Django Model copy with ManyToManyField
Trying to copy a Django model with ManyToManyField.
the model is
class Book(models.Model):
cats = models.ManyToMa开发者_JAVA技巧nyField(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
book.cats.all()
Example usage and docs.
精彩评论