Almost two months ago, I released the Django Dynamic Formset plugin, with the hope that someone out there might find it useful. Since then, I’ve received a good bit of feedback, which I’ve been meaning to roll into a new release. Last weekend, I finally made some time to update the documentation and examples, and today, I updated the project site on Google Code.
This new release contains two bugfixes (thanks to Wilson.Andrew.J and an anonymous fella), as well as a few more examples (thanks lfborjas). Here’s the short list of changes:
- Fixed bug that erased the values on all checkboxes/radiobuttons in a cloned form
- Fixed a bug in the way the “add new” event handler was being assigned (discoverd this while adding support for multiple formsets)
- Added support for multiple formsets on the same page — see documentation
- Added two new examples
- Updated the documentation
You can download the releases from the Google Code page, or use the links below:
- Source code, minified (using jsmin) version and docs
- Source code, minified version, docs and demo Django project
Big Thanks to all those who reported bugs, contributed patches or just left comments — you guys rock.
Stanislaus, this is a great plugin and I will be using it a lot. I have figured out a pretty easy way to add it to any Admin form. Add the following to templates/admin/APP/MODEL/change_form.html and make sure to change the prefix:
{% extends "admin/change_form.html" %} {% load i18n admin_modify adminmedia %} {% block extrahead %} {{ block.super }} // Define this so we don't have to bother with the admin jsi18n stuff: function gettext(msgid) { return msgid; } $(function() { $('.inline-related tbody tr').formset({ prefix: 'MODEL_set', addText: 'Add', deleteText: 'Delete', }); }); .add-row { padding-left:18px; background:url({% admin_media_prefix %}img/admin/icon_addlink.gif) no-repeat left center; } .delete-row { float:right; display:block; padding-left:18px; background:url({% admin_media_prefix %}img/admin/icon_deletelink.gif) no-repeat left center; } {% endblock %}@Justin: yep, overriding those admin templates is a pretty nifty trick. Thanks for the post and links.
When i click remove and post the form, the removed object is not deleted from the database. Do i need to include the delete checkbox in my form?
Clicking ‘remove’ just removes the form from the formset; it doesn’t delete the underlying object. To do that, you’ll need to pass ‘can_delete=True’ to the inlinemodelformset_factory, and display the ‘delete’ checkbox on the form, like you said.