The state of the Django Docs that you can display custom HTML for readonly fields in the admin interface. This is exactly what I need, but it does not work.
In admin.py:
from django.contrib import admin
class ExampleAdmin(admin.ModelAdmin):
readonly_fields = ('myfield', )
def myfield(self, instance):
print 'This part of the code is never reached!'
return u'<b>My custom html for the readonly field!</b>'
myfield.allow_tags = True
admin.site.register(State, StateAdmin)
In models.py:
class State(models.Model):
myfield = MyCustomField()
... etc ...
class MyCustomField(models.TextField):
def to_python(self, value):
... etc ...
The field appears as read-only on the admin edit page. However, the myfield method, which should create custom html, is never called.
Does anyone know what I'm doing wrong?
Yours faithfully,
Patrick
source
share