Save New Formset

Hello everyone,

I am playing with the django formset with pleasure.
No problem to use it and save changed value.

But I got a problem when I add information in the last line (the one use to add a new object)
This object have a foreignkey and the value is right insert in the fields for update but not in the field for new.
I can enter it manually but it is boring especialy because it s normaly known by the system
Here a small picture perhpas more easy to hunderstand :slight_smile:

And the result is when I save and jump to the, the individual object (the last one / the create one) has a non valid form because there is a missing field

forms = my_FormSet(request.POST)
for form in forms:
if form.is_valid()

Do you know how to solve this problem and create the object correctly ?

Thanks for your help and sorry for my bad english


If all the entries in the formset are going to have the same value, then I would create the formset without that field at all, and assign the necessary value for it when saving the individual form. If you want that field displayed on the screen, I’d render it as a “disabled” field and initialize it when creating the formset.
To some degree, exactly how this needs to be done will depend upon how you’re adding the row to the formset when a new entry is to be created.

(There’s no need for you to apologize for your English. Your English is far superior than my <any other language>, and we appreciate your efforts here.)