Answer the question
In order to leave comments, you need to log in
How to accept manyToMany data from a form?
Hello, I can’t find the reason why data from many2many fields is not accepted, data is sent, but the form does not save exactly this field
Here is the form
class MovieEdit(forms.ModelForm):
class Meta:
model = Movie
fields = ("actors", ...)
class Movie(models.Model):
actors = models.ManyToManyField(Actors, verbose_name=u'Выберите актеров')
if request.method == "POST":
movie = MovieEdit(request.POST, instance=movie)
if form.is_valid():
movie = form.save(commit=False)
movie.owner = request.user
movie.published_date = timezone.now()
movie.save()
return redirect('/my_movies/')
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