I am using formet with can_delete = True. I want to change the DELETE field widget to hidden input. I can't seem to find a good way to do this. I tried:
Change the form widget to HiddenInput and / or add a hidden field to the form definition:
class MyForm(ModelForm): DELETE = forms.BooleanField(widget=forms.HiddenInput) class Meta: model = MyModel widgets = {'DELETE' : forms.HiddenInput}
Do it with shape change
class MyFormSet(BaseModelFormSet): def add_fields(self, form, index): originalDeletion = None if DELETION_FIELD_NAME in form.fields: originalDeletion = form.fields[DELETION_FIELD_NAME] super(MyFormSet, self).add_fields(form,index) if originalDeletion is not None: form.fields[DELETION_FIELD_NAME] = originalDeletion
If I do this, it really changes the field to hidden, but it seems to be hacked (actually overwriting the usual add_fields method). How should you do this?
== EDIT ==
It turns out that using a hidden field is not so good with the shape framework anyway. You should definitely use the checkbox and hide it with css. If you want to edit the css of the checkbox in Django, I still think you need to change the add_fields method as above, and then you can change the css widget.
Blaise
source share