Django show readonly field
Add readonly field in Django admin, django does not show readonly fields by default.

Published At
3/25/2023
Reading Time
~ 1 min read
As seen in Add created_at and updated_at in base class, we can add automatic date and time fields in Django models. But, Django does not show these fields in admin by default. We need to add them manually.
Add readonly field in Django admin
pythonclass BaseAdmin(admin.ModelAdmin):
readonly_fields = ('created_at', 'updated_at')
class Meta:
abstract = True
pythonclass BaseAdmin(admin.ModelAdmin):
readonly_fields = ('created_at', 'updated_at')
class Meta:
abstract = True
and then add this class in admin.py
pythonclass MyModelAdmin(BaseAdmin):
pass
pythonclass MyModelAdmin(BaseAdmin):
pass
register the model with this admin class.
pythonadmin.site.register(MyModel, MyModelAdmin)
pythonadmin.site.register(MyModel, MyModelAdmin)
🐣🐣🐣
Do you have any questions, or simply wish to contact me privately? Don't hesitate to shoot me a DM on Twitter.
Have a wonderful day.
Abhishek 🙏