[Solved]-Accessing Many to Many "through" relation fields in Formsets

17👍

As you’re probably aware, you can’t edit many-to-many relationships with inline formsets. You can, however, edit the through model. So for your inline formset, you just need to set the model to the through model, e.g.:

inlineformset_factory(Phone_Client, Line.phone_client.through)

line_index will actually be a visible field on the inline form, so you really don’t have to do anything. If someone changes the index, it’ll be saved when the inline forms are saved, just like the rest of the fields.

Leave a comment