How to check if the form is edit/view/create form in a template for Django admin

Viewed 385

I want to customize the view only template in Django admin and want to add custom CSS class if the user opens the view only form (for example class="test_class").

I tried this to change the class for edit form so I can use the default one for add and change templates: Can I tell if a form is an 'edit' form in a template? but it doesn't work. I don't see my custom class when I inspect the form.

I want to know if there is a more "cleaner" solutions than this: How to add css class to Django admin form

For example (this is a pure guess) something like this in change_form.html:
<form {% if form.is_change_form %} class="test_class" {% endif %}

0 Answers
Related