Django Forms save_m2m
        Posted  
        
            by 
                John
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by John
        
        
        
        Published on 2009-12-23T14:20:34Z
        Indexed on 
            2011/01/09
            11:53 UTC
        
        
        Read the original article
        Hit count: 233
        
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
© Stack Overflow or respective owner