一个用于选择通用模型(而不是片段或页面)的Wagtail应用。
项目描述
一个用于选择通用模型(而不是片段或页面)的Wagtail应用。
这是alpha软件,使用时请自担风险。请勿在生产环境中使用(目前还不行)。
查看Awesome Wagtail以获取来自Wagtail社区的更多优秀包和资源。
安装
使用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中选择模型,分别使用RemoteModelChooserBlock和RemoteModelChooserPanel。
如果您已安装WagtailDraftail,它将自动将ModelSource和RemoteModelSource注册到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
}
}
开发
安装
要求:virtualenv,pyenv,twine
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__.py 和 package.json 中更新版本号,遵循 semver。
创建一个 PR 并将其合并。
在 PR 合并到 master 后,使用 make publish(确认并输入您的密码)。
最后,前往 GitHub 为新版本创建一个发布和标签。
完成!
项目详情
下载文件
下载适合您平台的项目文件。如果您不确定选择哪个,请了解更多关于 安装包 的信息。
源代码分发
wagtailmodelchoosers-0.1.2.tar.gz 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 66d855ae141d3c0c2d88812e1c4623f68d8bd6f16455e2a51d86d859125bdbbb |
|
MD5 | e3e6a6a773b1f7d2c8e7745a5f14c1bb |
|
BLAKE2b-256 | c37fbd96578d7cc369e16581afaf9a1a7f6cb2c7fde383b3720c1bec48370587 |