跳转到主要内容

一个用于选择通用模型(而不是片段或页面)的Wagtail应用。

项目描述

一个用于选择通用模型(而不是片段或页面)的Wagtail应用。

这是alpha软件,使用时请自担风险。请勿在生产环境中使用(目前还不行)。

查看Awesome Wagtail以获取来自Wagtail社区的更多优秀包和资源。

https://cdn.rawgit.com/springload/wagtailmodelchoosers/b7b6202/.github/wagtailmodelchoosers-screenshot.png

安装

使用pip安装包:pip install wagtailmodelchoosers,然后在您的设置中的INSTALLED_APPS中添加wagtailmodelchoosers

用法

ModelChooserBlock将选择器配置的名称作为第一个位置参数。使用其他块关键字参数(例如required)如常。

from wagtail.wagtailcore import blocks
from wagtailmodelchoosers.blocks import ModelChooserBlock

class CustomBlock(blocks.StructBlock):
    custom_model = ModelChooserBlock('custom_model')  # `chooser` can be a positional argument, the keyword is used here for clarity.

ModelChooserPanel将字段名称作为第一个位置参数(就像一个常规面板一样),并将选择器配置的名称作为第二个位置参数。使用其他面板关键字参数如常。

from django.db import models
from wagtail.core.models import Page
from wagtailmodelchoosers.edit_handlers import ModelChooserPanel

class CustomPage(Page):
    custom_model = models.ForeignKey('myapp.CustomModel')

    panels = [
        ...
        ModelChooserPanel('custom_model', chooser='custom_model'),  # `chooser` can be a positional argument, the keyword is used here for clarity.
    ]

要从远程API中选择模型,分别使用RemoteModelChooserBlockRemoteModelChooserPanel

如果您已安装WagtailDraftail,它将自动将ModelSourceRemoteModelSource注册到JS中。有关正确连接的说明,请参阅WagtailDraftail文档

配置

它在设置中寻找名为MODEL_CHOOSERS_OPTIONS的字典,其中键是选择器的名称,值是选项的字典。

ModelChooser 和 RemoteModelChooser 具有相似的基本配置,只有少数几个特定字段。

MODEL_CHOOSERS_OPTIONS = {
    'navigation': {
        'label': 'Navigation',                                   # The label to use for buttons or modal title
        'display': 'name',                                       # The field to display when selecting an object
        'list_display': [                                        # The fields to display in the chooser
            {'label': 'Name', 'name': 'name'},
            {'label': 'Identity', 'name': 'identity'},
            {'label': 'Active', 'name': 'active'},
        ],
        'content_type': 'core.Navigation',                       # ONLY FOR MODEL: The django content type of the model
        'fields_to_save': ['id'] + RATE_CHOOSER_DISPLAY_FIELDS,  # ONLY FOR REMOTE: The remote objects fields to save to the DB. Leave empty to save the whole object.
        'remote_endpoint': 'http://...'                          # ONLY FOR REMOTE: The remote API endpoint.
        'pk_name': 'uuid',                                       # The primary key name of the model
    }
}

此外,您还可以自定义 API 键的映射,查看用于 查询响应 的配置键名称。

开发

安装

要求:virtualenvpyenvtwine

git clone git@github.com:springload/wagtailmodelchoosers.git
cd wagtailmodelchoosers/
virtualenv .venv
source ./.venv/bin/activate
pip install -e .[testing,docs] -U
nvm install
npm install

命令

make help            # See what commands are available.

待办:完成

版本发布

  • 为新的版本发布创建一个新的分支。

  • 更新 CHANGELOG

  • wagtailmodelchoosers/__init__.pypackage.json 中更新版本号,遵循 semver。

  • 创建一个 PR 并将其合并。

  • 在 PR 合并到 master 后,使用 make publish(确认并输入您的密码)。

  • 最后,前往 GitHub 为新版本创建一个发布和标签。

  • 完成!

项目详情


下载文件

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

源代码分发

wagtailmodelchoosers-0.1.2.tar.gz (285.6 kB 查看哈希值)

上传时间 源代码

由以下机构支持