3

I want to customize django admin change_list_result row content, so i guess override related to change_list_result function.

And I found to konw call display_for_field via items_for_result in django.contrib.admin.templatetags.admin_list. admin_list.py

I put following code to the manage.py, but doesn't work.

from django.contrib.admin.utils import display_for_field
from warehouse.monkey_patching import _display_for_field_mod

display_for_field = _display_for_field_mod

1 Answer 1

2

Here you override the local variable dispaly_for_field. If you want to override it, you need to set the attribute of the module:

from django.contrib.admin import utils
from warehouse.monkey_patching import _display_for_field_mod

utils.display_for_field = _display_for_field_mod

As you probably already know, you must make sure that you monkey patch the function before other modules import it, since otherwise, these will obtain a reference to the "old" function. You thus probably should import this as (one of the) first lines in your manage.py file.

Sign up to request clarification or add additional context in comments.

1 Comment

Because here we alter the function in the module, not the local identifier.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.