跳转到主要内容

在list_display中使用'__'允许外键属性

项目描述

https://travis-ci.org/PetrDlouhy/django-related-admin.svg?branch=master https://coveralls.io/repos/github/PetrDlouhy/django-related-admin/badge.svg?branch=master https://badge.fury.io/py/django-related-admin.svg

在Django管理更改列表list_display中使用'__'允许外键属性

这是基于DjangoSnippet 2996,由Kpacn制作。

安装

  1. 此库位于PyPI,因此您可以使用以下方式安装它

    pip install django-related-admin

或从GitHub

pip install git+https://github.com/PetrDlouhy/django-related-admin#egg=django-related-admin
  1. 将“related_admin”添加到您的INSTALLED_APPS设置中,如下所示

    INSTALLED_APPS = (
        ...
        'related_admin',
        'django.contrib.admin',
    )

注意:Django-related-admin更改change_list.html模板,以禁用admin标题上的white-space: nowrap; CSS类,以允许长(可能相关的)标题名称换行。如果您想这样做,请在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)

项目详情


下载文件

下载适用于您的平台的文件。如果您不确定选择哪个,请了解更多关于安装软件包的信息。

源分布

django-related-admin-1.0.1.tar.gz (11.2 kB 查看哈希值)

上传时间:

支持