30👍
✅
Like that (from memory):
class AddressAdmin(admin.ModelAdmin):
fieldsets = [(label, {'fields': ['address','address_2_html']}),]
readonly_fields = ['address_2_html']
def address_2_html(self, obj):
return obj.address_2_html()
address_2_html.allow_tags = True
address_2_html.short_description = 'Address display'
2👍
Problem solved by overriding get_fieldsets() since the get_fieldsets() method allows access to the model object Address.
def get_fieldsets(self, request, obj=None):
fs = [
(self.label, {'fields': ['address',]}),
('Map', {'fields': [], # required by django admin
'description':obj.address_2_html(),
}),
]
return fs
- The default "delete selected" admin action in Django
- Django: Faking a field in the admin interface?
- How to test a Django on_commit hook without clearing the database?
- Django's get_current_language always returns "en"
- Creating UTF-8 JsonResponse in Django
Source:stackexchange.com