Sometimes, we want to display a field that is marked as editable=False’ in the model with Python Django admin.
In this article, we’ll look at how to display a field that is marked as editable=False’ in the model with Python Django admin.
How to display a field that is marked as editable=False’ in the model with Python Django admin?
To display a field that is marked as editable=False’ in the model with Python Django admin, we add them to the readonly_fields
tuple.
For instance, we write
class MyModelAdmin(admin.ModelAdmin):
readonly_fields=('first',)
to add the 'first'
read only field into our model admin class.
Conclusion
To display a field that is marked as editable=False’ in the model with Python Django admin, we add them to the readonly_fields
tuple.