1👍
You can disable the field by setting the disabled
attribute [Django-doc] to True
:
form.fields['groups'].queryset = models.Group.objects.all()
form.fields['groups'].initial = models.Group.objects.filter(is_default=True)
form.fields['groups'].disabled = True
If you set this while constructing the form (in the __init__
method), it will also prevent people from making "forged" POST requests with a different value. In other words: this does not only disables the field at the browsers client, but also prevents malicious requests.
Source:stackexchange.com