[Answer]-Django: How can I render a ModelForm partially editable fields and show other fields as label items?

1👍

For show all fields try use __all__ in Meta:

class SolicitanteForm(ModelForm):

    class Meta:
        model = Solicitante
        fields = '__all__'

For displaying the form fields is responsible widgets. So you need write own widget with necessary behavior.

In this post, author solved a similar problem, maybe it will be helpfull

0👍

You can use readonly HTML attribute. It will make the input tabbable but not usable. In HTML:

<input type="text" name="congregacionOfertante" value="Cameroon" readonly>

You can custom you form as following for add the HTML attribute:

class SolicitanteForm(forms.ModelForm):
    class Meta:
        model = Solicitante
        fields = ['congregacionOfertante', 'id_oferta', 'observaciones', 'descartado']
        widgets = {
            'congregacionOfertante': forms.TextInput({'readonly': 'readonly'})
        }

Ref: HTML readonly Attribute

If you don’t want it clickable/selectable use disabled attribute.

👤Zulu

Leave a comment