1👍
✅
Your class in admin.py should be like below. Please use get_readonly_fields
to do this.
class EmployeeAdmin(admin.ModelAdmin):
search_fields = ['name']
list_display = ('name','id','dob','bill','mobile','email')
list_filter = ('bill','proj')
# readonly_fields=('id',)
def get_readonly_fields(self, request, obj=None):
if obj: # editing an existing object
return self.readonly_fields + ('id',)
return self.readonly_fields
Source:stackexchange.com