views:

175

answers:

2

I have a Django Model with a text field. I would like to modify the content of the text field before it's presented to the user in Django Admin.

I was expecting to see signal equivalent of post_load but it doesn't seem to exist.

To be more specific:

I have a text field that takes user input. In this text field there is a read more separator. Text before the separator is going to go into introtext field, everything after goes into fulltext field.

At the same time, I only want to show the user 1 text field when they're editing the article.

My plan was to on_load read the data from introtext and fulltext field and combine them into fulltext textarea. On pre_save, I would split the text using the read more separator and store intro in introtext and remainder in fulltext.

So, before the form is displayed, I need to populate the fulltext field with

introtext + '<!--readmore-->' + fulltext

and I need to be able to do this for existing items.

+2  A: 

Have a look into Providing your own form for the admin pages.

Once you have your own form, you can use the default param in the form to provide the initial value you want. See the docs on the Initial param for the form field. As this link will show you, it is possible to use a callable or a constant as your initial value.

Tom Leys
A: 

There is no post_load because there is no load function.

Loading of the instance is done in init function, therefore the right answer is to use post_init signal.

tarasm