old_contents: from django import forms
  
  
  class KnockoutModelForm(forms.ModelForm):
  
      def __init__(self, *args, **kwargs):
          super(KnockoutModelForm, self).__init__(*args, **kwargs)
  
          if hasattr(self, 'knockout_field_names'):
              knockout_field_names = self.knockout_field_names
          else:
              knockout_field_names = {}
  
          if hasattr(self, 'knockout_exclude'):
              knockout_exclude = self.knockout_exclude
          else:
              knockout_exclude = []
  
          if hasattr(self, 'knockout_init'):
              knockout_init = self.knockout_init
          else:
              knockout_init = False
  
          for field in self:
              if field.name in knockout_exclude:
                  continue
  
              attr = ""
  
              if knockout_init:
                  attr = "init, "
  
              widget_name = field.field.widget.__class__.__name__
              if widget_name in ['CheckboxInput']:
                  attr += "click: $root.clickChecked, checked: "
              elif widget_name in ['ClearableFileInput']:
                  attr += "event: { change: "
              else:
                  attr += "value: "
  
              if field.name in knockout_field_names:
                  attr += knockout_field_names[field.name]
              else:
                  attr += field.name
  
              if widget_name in ['ClearableFileInput']:
                  attr += "Change }"
  
              field.field.widget.attrs['data-bind'] = attr
  
new_contents: from django import forms
  from django.forms import formsets
  
  
  class KnockoutModelForm(forms.ModelForm):
  
      def __init__(self, *args, **kwargs):
          super(KnockoutModelForm, self).__init__(*args, **kwargs)
  
          if hasattr(self, 'knockout_field_names'):
              knockout_field_names = self.knockout_field_names
          else:
              knockout_field_names = {}
  
          if hasattr(self, 'knockout_exclude'):
              knockout_exclude = self.knockout_exclude
          else:
              knockout_exclude = []
  
          if hasattr(self, 'knockout_init'):
              knockout_init = self.knockout_init
          else:
              knockout_init = False
  
          for field in self:
              if field.name in knockout_exclude:
                  continue
  
              attr = ""
  
              if knockout_init:
                  attr = "init, "
  
              widget_name = field.field.widget.__class__.__name__
              if widget_name in ['CheckboxInput']:
                  attr += "click: $root.clickChecked, checked: "
              elif widget_name in ['ClearableFileInput']:
                  attr += "event: { change: "
              else:
                  attr += "value: "
  
              if field.name in knockout_field_names:
                  attr += knockout_field_names[field.name]
              else:
                  attr += field.name
  
              if widget_name in ['ClearableFileInput']:
                  attr += "Change }"
  
              field.field.widget.attrs['data-bind'] = attr
  
  
  class KnockoutBaseInlineFormSet(forms.BaseInlineFormSet):
      def add_fields(self, form, index):
          super(KnockoutBaseInlineFormSet, self).add_fields(form, index)
  
          attr = 'checked: DELETE'
          delete_field = form.fields[formsets.DELETION_FIELD_NAME]
          delete_field.widget.attrs['data-bind'] = attr
          delete_field.widget.attrs['class'] = 'formset-delete'
  
subject: add KnockoutBaseInlineFormSet to automatically add a data-bind and class to django DELETE input checkboxes