C
C
Cyber_bober2016-11-29 16:14:49
Django
Cyber_bober, 2016-11-29 16:14:49

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", ...)

This is how I keep
class Movie(models.Model):
    actors = models.ManyToManyField(Actors, verbose_name=u'Выберите актеров')

And this is how I process
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/')

Tell me, what could be the reason?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question