How to make a form field read only (readonly) in django if I have a select in the form type ModelChoiceField , and in the Model it is equivalent to an attribute type ForeignKey been dealing with this but it does not work:
class CostoForm (forms.ModelForm):
"""
Edicion de Costos con formset.
"""
class Meta:
model = Costo
exclude = ('user', )
def __init__(self, *args, **kwargs):
super(CostoForm, self).__init__(*args, **kwargs)
self.helper = FormHelper()
self.helper.form_tag = False
self.helper.form_action = ''
self.helper.form_class = 'form-inline'
self.helper.template = 'crispy_template/table_inline_formset.html'
self.helper.layout = Layout(
Field('DELETE', css_class='btn btn-primary')
)
self.helper.add_input(Submit('submit', _('Aceptar')))
self.fields['destination'].widget.attrs['readonly'] = True