Well, yes, there is that - e.g. the fk_groupe. (And fk_client I guess, but that’s dealt with when I save the form, formset.instance = self.object). But that’s not really the crux of the matter for me.
The crux of the matter is that each form instance in the formset corresponds to 1 entry in MetaGroup table (e.g. Plastic cable, LED lights, etc.). Thus that means that the fk_groupe for each form in the formset must be set to the MetaGroup instance’s pk. So I guess that either in the template, or in an inclusion_tag, or the form view, or perhaps class DiscountForm, I need to:
- Fetch the content of the MetaGroup table
- create/add a form to the formset corresponding each entry returned (LED Lights, Plastic cable, etc.)
- set the fk_group for that form
But then, the inlineformset_factory produces forms within a formset, but none of those forms will have any fk_groupe assigned. So somehow I would have to assign them at some point, but I’m not sure what hook I have to actually do that. So my current approach would be to make that information (a list of fk_groupe) available in the context to the template, and then assign it to each form instance as I iterate? (Or javascript would work & just .val() on each td).
I’m getting the pieces toghether to make that work. Thought it does seem complicated. I’m not really sure where I want to put the logic for that either.