尝试使用ManyToManyField复制Django模型。
模型是
class Book(models.Model):
cats = models.ManyToManyField(Category)
观点:
for book in books:
book.name = "New Name"
messageinfo = message.save()
msg = Book(title=book.title, subject=book.subject)
msg.save()
直到这里的作品,制作一本书
以下内容出现错误
for cat in book.cats:
info = Category.objects.get(id=cat.id)
msg.cats.add(info)
产生错误
TypeError at /
'ManyRelatedManager' object is not iterable