I'm developing a Django project in which I want to allow users to edit a specific field only on add_view. So I've overridden the change_view method on the admin.py so it can set my readonly_fields there. However Django won't display readonly_fields.
It seems really wird for me that a readonly field is not displayed. I mean, if it's readonly, where is the part of it where it says read? It should be readable (only), and not ediable. If I wanted to hide it, there should be an option called hidden_fields or something. Don't you guys agree?
I wonder if is there any straighforward way of make readonly_fields visible on my admin, but not ediable.
my admin.py looks like this:
from django.contrib import admin from core.models import Box
class BoxAdmin(admin.ModelAdmin):
def change_view(self, request, object_id, form_url='', extra_context=None):
self.readonly_fields = ('colour',)
return super(BoxAdmin, self).change_view(request, object_id)
def add_view(self, request, form_url='', extra_context=None):
self.readonly_fields = []
return super(BoxAdmin, self).add_view(request, extra_context=c)
readonly_fields = ('colour',)tuple to yourBoxAdminclass? From docs - Gochtfieldsorfieldsets,readonly_fieldsappear at the bottom, after all editable fields. - Paulo Almeida