允许列表中的外键属性显示为“\uu”
django-related-admin的Python项目详细描述
允许Django管理更改列表中的外键属性list_display使用'\uuu'
这是基于kpacn制作的DjangoSnippet 2996。
安装
此库位于pypi上,因此您可以使用以下命令安装它:
pip install django-related-admin
或来自github:
pip install git+https://github.com/PetrDlouhy/django-related-admin#egg=django-related-admin
将“相关管理员”添加到已安装的应用程序设置中,如下所示:
INSTALLED_APPS = ( ... 'related_admin', 'django.contrib.admin', )
注意:django相关的管理更改change_list.html模板以禁用white-space: nowrap; 管理头上的css类,以允许长(位置相关的)头名称换行。 如果您想要此行为,请在django.contrib.admin之前添加应用程序,否则在django.contrib.admin之后添加应用程序。
用法
只需使用它而不是model.admin:
from related_admin import RelatedFieldAdmin from related_admin import getter_for_related_field class FooAdmin(RelatedFieldAdmin): # these fields will work automatically (and boolean fields will display an icon): list_display = ('address__phone','address__country__country_code','address__foo') # ... but you can also define them manually if you need to override short_description or boolean parameter: address__foo = getter_for_related_field('address__foo', short_description='Custom Name', boolean=True)