views:

355

answers:

1

Hi I have a model which has 2 many to many fields in it. one is a standard m2m field which does not use any through tables whereas the other is a bit more complecated and has a through table. I am using the Django forms.modelform to display and save the forms. The code I have to save the form is

if form.is_valid():
        f = form.save(commit=False)
        f.modified_by = request.user
        f.save()
        form.save_m2m()

When i try to save the form I get the following error:

Cannot set values on a ManyToManyField which specifies an intermediary model.

I know this is happening when I do the form.save_m2m() because of the through table. What I'd liek to do is tell Django to ignore the m2m field with the through table but still save the m2m field without the through table. I can then go on to manually save the data for the through table field.

Thanks

A: 

you can't save the m2m "without the through table"

the data you want to save is stored in the through table (and only in the through table)

Jiaaro