sorry, I failed to pass the request to the view's function,..

Le 04/03/2011 22:08, werefr0g a écrit :
On Thu, Mar 3, 2011 at 11:50 AM, werefr0g <weref...@yahoo.fr> wrote:
Hello,

Sorry if I misunderstand, but what is wrong about using a ModelForm on your
Film bounded to the film instance?
My bad... how did I missed the intermediary model involved in the ManyToMany relashionship. Sorry.

When I tried that I kept running into this error:
   "Cannot set values on a ManyToManyField which specifies an
intermediary model.  Use foo.FilmRole's Manager instead.
As you are using an intermediary model, you must insert multiple FilmRole, one for each actor to this film, but you don't want using a formset, do you?.

Is the following going toward your goal?

# forms.py
class FilmActorsForm(forms.Form):
actors = forms.ModelMultipleChoiceField(queryset=Actors..., required=...)

# views.py
def assign_actors(film_id):
    film = get_object_or_404(Film, id=film_id)
    if request.method == 'POST':
        form = FilmActorsForm(request.POST)
        if form.is_valid():
            chosen_actors = form.cleaned_data['actors']
            current_actors = film.actors.all()
            # handle deletion / creation of filmroles
            return HttpResponseRedirect(...)
    else:
        form = FilmActorForm()

Regards,

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to