'Returns a BaseInlineFormSet class for use in admin add/change views.'

def get_formset(self, request, obj=None, **kwargs):

    if ('fields' in kwargs):
        fields = kwargs.pop('fields')
    else:
        fields = flatten_fieldsets(self.get_fieldsets(request, obj))
    if (self.exclude is None):
        exclude = []
    else:
        exclude = list(self.exclude)
    exclude.extend(self.get_readonly_fields(request, obj))
    if ((self.exclude is None) and hasattr(self.form, '_meta') and self.form._meta.exclude):
        exclude.extend(self.form._meta.exclude)
    exclude = (exclude or None)
    can_delete = (self.can_delete and self.has_delete_permission(request, obj))
    defaults = {'form': self.form, 'formset': self.formset, 'fk_name': self.fk_name, 'fields': fields, 'exclude': exclude, 'formfield_callback': partial(self.formfield_for_dbfield, request=request), 'extra': self.get_extra(request, obj, **kwargs), 'max_num': self.get_max_num(request, obj, **kwargs), 'can_delete': can_delete}
    defaults.update(kwargs)
    base_model_form = defaults['form']
    class DeleteProtectedModelForm(base_model_form, ):
        def hand_clean_DELETE(self):
            '\n                                                                We    don\'t    validate    the    \'DELETE\'    field    itself    because    on\n                                                                templates    it\'s    not    rendered    using    the    field    information,    but\n                                                                just    using    a    generic    "deletion_field"    of    the    InlineModelAdmin.\n                                                                '
            if self.cleaned_data.get(DELETION_FIELD_NAME, False):
                using = router.db_for_write(self._meta.model)
                collector = NestedObjects(using=using)
                collector.collect([self.instance])
                if collector.protected:
                    objs = []
                    for p in collector.protected:
                        objs.append((_('%(class_name)s    %(instance)s') % {'class_name': p._meta.verbose_name, 'instance': p}))
                    params = {'class_name': self._meta.model._meta.verbose_name, 'instance': self.instance, 'related_objects': get_text_list(objs, _('and'))}
                    msg = _('Deleting    %(class_name)s    %(instance)s    would    require    deleting    the    following    protected    related    objects:    %(related_objects)s')
                    raise ValidationError(msg, code='deleting_protected', params=params)
        def is_valid(self):
            result = super(DeleteProtectedModelForm, self).is_valid()
            self.hand_clean_DELETE()
            return result
    defaults['form'] = DeleteProtectedModelForm
    if ((defaults['fields'] is None) and (not modelform_defines_fields(defaults['form']))):
        defaults['fields'] = forms.ALL_FIELDS
    return inlineformset_factory(self.parent_model, self.model, **defaults)
