选择通用模型(而不是代码片段或页面)的wagtail应用程序
wagtailmodelchoosers的Python项目详细描述
A Wagtail app to pick generic models (rather than snippets or pages).
这是alpha软件,使用风险自负。不要在生产中使用(尚未)。
查看Awesome Wagtail了解更多来自wagtail社区的优秀软件包和资源。
安装
从pip中获取带有pip install wagtailmodelchoosers的包,然后在设置中的INSTALLED_APPS中添加wagtailmodelchoosers。
用法
ModelChooserBlock将选择器配置的名称作为第一个位置参数。像往常一样使用其他块度(例如,必需的)。
fromwagtail.wagtailcoreimportblocksfromwagtailmodelchoosers.blocksimportModelChooserBlockclassCustomBlock(blocks.StructBlock):custom_model=ModelChooserBlock('custom_model')# `chooser` can be a positional argument, the keyword is used here for clarity.
ModelChooserPanel将字段的名称作为第一个位置参数(如常规面板),将选择器配置的名称作为第二个位置参数。像往常一样使用其他面板。
fromdjango.dbimportmodelsfromwagtail.core.modelsimportPagefromwagtailmodelchoosers.edit_handlersimportModelChooserPanelclassCustomPage(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,它将自动向js注册ModelSource和RemoteModelSource。请参阅WagtailDraftail'sdocumentation以正确连接它。
配置
它在设置中查找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。
- 根据semver更新wagtailmodelchoosers/__init__.py和package.json中的版本号。
- 做一个公关和挤压合并它。
- 回到合并了pr的master上,使用make publish(确认并输入密码)。
- 最后,转到github并为新版本创建一个版本和一个标记。
- 完成!