Categories
Python Answers

How to display a field that is marked as editable=False’ in the model with Python Django admin?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *