How to prevent model formset from saving the empty forms?

186 views
Skip to first unread message

Joshua Russo

unread,
Aug 9, 2011, 11:51:02 PM8/9/11
to django...@googlegroups.com
I have a model formset that's displaying an extra form, but when I save I always get that form saved as an empty entry. How do I tell it not to save the model forms that I don't edit? It doesn't happen this way in the admin, does it?

Joshua Russo

unread,
Aug 10, 2011, 12:26:54 AM8/10/11
to django...@googlegroups.com
Ok, I figured out why, but I still don't know how to fix it. 

I set a dropdown to empty_label = None, which automatically selects the first element. I want that, but the form then thinks it has changed because the value in the list of initial values is empty for that field, and I can't see how to set the initial value for the forms in a model formset.

Any suggestions?

Joshua Russo

unread,
Aug 10, 2011, 12:33:22 AM8/10/11
to django...@googlegroups.com
Nm, I got it

Joshua Russo

unread,
Aug 10, 2011, 12:34:10 AM8/10/11
to django...@googlegroups.com
I just needed to retrieve the first pk value from the field's queryset in the init of the form and set the initial value there.
Reply all
Reply to author
Forward
0 new messages