Skip to main content

一个 Django 应用程序,允许只读管理员内联,而与基本模型无关

项目描述

Django 模拟内联

使用 Spacemacs 构建

描述

这个包扩展了 ModelAdmin 接口,可以创建自定义内联,该内联可以包含任何模型实例的列表,不需要与基本 change_form 的关系。

特征

  • 内联可以折叠
  • 支持内嵌字幕
  • 分页
  • 任何内联单元格的自定义链接
  • 动态字段
  • 动作按钮

安装

  1. 安装:pip install django_simulated_inlines
  2. 添加到 INSTALLED_APPS:
    INSTALLED_APPS = [
        ...
        'django_simulated_inlines',
    ]

如何使用

  • 导入 ModelAdmin 和 Inline 类

from django_simulated_inlines.admin import SimulatedInline, SimulatedInlinesModelAdmin

  • 声明内联:
class ExampleInline(SimulatedInline):
    model = ExampleModel
    verbose_name = _("example")
    verbose_name_plural = _("examples")
    per_page = 20
    buttons = ("example_button", )
    collapse = True
    fields = (
        "id"
        ("custom_link", "/admin/custom/link/%s/"),
        "custom_field",
    )

    def custom_field(self, obj):
        """The return of this function is the value on the field cell"""
        return f"Custom field for {self.field}"
    custom_field.short_description = _("custom field")

    def example_button(self, request, object_id):
        """This function is called when the button is pressed"""
        execute_code()
    example_button.short_description = _("Execute example button")

    def get_subtitle(self, request, object_id):
        """Override this to define a subtitle for the inline"""
        return "this is a subtitle"

    def get_queryset(self, request, object_id, parent_queryset):
       """Override this to filter or customize de queryset"""
       return self.model.objects.filter(x=object_id).all()
  • 将内联添加到 SimulatedInlinesModelAdmin.simulated_inlines.
class ExampleModelAdmin(SimulatedInlinesModelAdmin):
    simulated_inlines = [ExampleSimulatedInline]

要求

项目详情


下载文件

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

源分布

django_simulated_inlines-0.1.tar.gz (8.8 kB 查看哈希)

已上传 source

内置分布

django_simulated_inlines-0.1-py3-none-any.whl (8.8 kB 查看哈希

已上传 py3