The data stored in the database is HTML. I cannot change this fact, but I want to hide it in my django admin site.
Before the database populates the model, I’d like to capture it and convert the html entities to unicode. When the model is saved to the database I’d like to reverse the process.
I can do the actual conversion from HTML entity to unicode and the other way round, but I don’t know Django well enough to accomplish this.
I’ve looked into a modelform for the admin, but this will not work for when the data is displayed in the list_display or other places on the site.
Where/how is the best way to hook into this?
Look into making a
custom fieldif you want it automatically to anything that calls/saves this field. Specifically, set your database-to-model conversion into_python, and model-to-database conversion inget_prep_value.If this is behavior specifically for one area of the admin, you could also set it all in the
ModelAdmin.list_displaycan point to readonly fields which can do whatever it wants to the output.Pure admin: