Answer the question
In order to leave comments, you need to log in
How to save ManyToMany model in django ORM?
It is not possible to save data to a table with a many-to-many relationship. I save
it like this:
new_subscriber = EventToSubscriber(event=event_id, subscriber=current_user)
new_subscriber.save()
class EventToSubscriber(Model):
event = models.ManyToManyField(Event, verbose_name='Событие')
subscriber = models.ManyToManyField(User, verbose_name='Подписчик')
TypeError at /subscribe/4
Direct assignment to the forward side of a many-to-many set is prohibited. Use event.set() instead.
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question