Django – ManyToManyField 에 리스트 값 할당
아래와 같은 ManyToManyField 필드에 값을 대입하고 싶을때 그냥,
products = models.ManyToManyField(Product, blank=True)
item.products = body.products
이런식으로 했더니, 아래와 같이 에러 발생
The direct assignment to the forward side of a many-to-many set is not allowed. Instead, it is recommended to use the products.set() method for assigning values.
즉, 해결하려면 아래와 같은 구문을 사용해야 함.
item.products.set(body.products)
Enjoy Reading This Article?
Here are some more articles you might like to read next: