Using Django 1.9.9, Python 2.7
I am trying to figure out why I am not able to delete form/instance inside of FormSet. I was folowing debug to this function in django.forms.formsets.py line 300.
def _should_delete_form(self, form): """ Returns whether or not the form was marked for deletion. """ return form.cleaned_data.get(DELETION_FIELD_NAME, False)
In my case:
form.cleaned_data = {'name': 2, 'file': FieldFile: real_estate_1/podpis.html} data = { u'contracts-0-DELETE': [u'on'], ...} changed_data = [[u'DELETE'], ...]
... The main problem is that cleaned_data missing the DELETE field. The formset has self.can_delete = True
. But I am not able to figure out why the field is missing there...?
I would appreciate any advice.
My classes look this:
class DocumentsForm(CustomModelForm): file = forms.FileField(label=_(u'Smlouva'), required=True) empty_permitted = False class Meta: model = Contract fields = ['name', 'file'] fields_with_permissions = ['file'] class RequestInlineFormSet(BaseGenericInlineFormSet): formset = 'contracts' empty_permitted = False def __init__(self, *args, **kwargs): self.request = kwargs.pop('request', None) form_kwargs = {'request': self.request} super(RequestInlineFormSet, self).__init__(form_kwargs=form_kwargs, *args, **kwargs) ContractFormSet = generic_inlineformset_factory(Contract, form=DocumentsForm, formset=RequestInlineFormSet, can_order=False, can_delete=True, fields=('name', 'file'), extra=1)
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/f627799e-2626-4823-8927-f64aa1fc2ac9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment