2👍
✅
Turned out, I needed here the following code:
self.fields['field_name'].widget.attrs['disabled'] = 'disabled'
1👍
This option will remove the instance from the form fields when you submit the form.
self.fields['field_name'].widget.attrs['disabled'] = 'disabled'
Using this option you will disable de field to be edited and you can converse the init instance to be saved into the database.
algorithm = forms.ModelChoiceField(label='Algoritmo',queryset=Algorithm.objects.all(),to_field_name="name",widget=forms.TextInput(attrs={'readonly':'readonly'}))
- [Django]-Hue installation issue
- [Django]-Why is Django testrunner not finding the tests I created?
- [Django]-Django ORM migration giving "ValueError: invalid literal for int()" on IntegerField
- [Django]-{% extends "base.html" %} and {% block content %} inside if statement (Django app)
Source:stackexchange.com