1👍
✅
The ManyToMany manager assumes that when you do
tour.subscribers = sub
sub
is a sequence (tuple, list, queryset) of Subscribers
, not a single object. Then doing so is the exact same as doing:
tour.subscribers.add(*sub)
And since sub is not a sequence, it throws such error. I would recommend saving first and adding later. I think it’s also more readable, but it may be just my opinion:
sub = Subscribers()
tour = Tour()
tour.id = "1"
tour.name = "hello"
tour.owner_id = user1
tour.save()
tour.subscribers.add(sub)
Hope this helps 🙂
Source:stackexchange.com