选择通用模型(而不是代码片段或页面)的wagtail应用程序

wagtailmodelchoosers的Python项目详细描述


A Wagtail app to pick generic models (rather than snippets or pages).

这是alpha软件,使用风险自负。不要在生产中使用(尚未)。

查看Awesome Wagtail了解更多来自wagtail社区的优秀软件包和资源。

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

安装

从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中选择模型,请分别使用RemoteModelChooserBlockRemoteModelChooserPanel

如果安装了WagtailDraftail,它将自动向js注册ModelSourceRemoteModelSource。请参阅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}}

此外,还可以自定义api键的映射,查看用于queryresponse的配置键名称。

开发

安装

要求: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
  • 根据semver更新wagtailmodelchoosers/__init__.pypackage.json中的版本号。
  • 做一个公关和挤压合并它。
  • 回到合并了pr的master上,使用make publish(确认并输入密码)。
  • 最后,转到github并为新版本创建一个版本和一个标记。
  • 完成!

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
如何使用外部java程序在minecraft中移动minecraft角色的相机   java输出文本文件中的变量   java LazyLoadingException在我尝试从多通关系获取对象时出现   java json rest API的错误:ClassCastException:org。json。无法将JSONObject强制转换为组织。json。杰索纳雷   java BigInteger。C中的intValue()等价物#   java大写所有字符,但不包括带引号字符串中的字符   java获取特殊字符   javascript为什么Selenium中的所有getX()调用都需要这么长时间?   rabbitmq rabbitmq java客户端并行消费   如何使用selenium Java在popover窗口中提取文本   对象在java中构造一类对象   java Room数据库未实现   json JSONObject可以使用java保存大的格式化双值吗?   有时限的旅行推销员   java HttpsURLConnection openConnection查询   java无法使用Spring@Entity注释创建MySQL表   lambda Java 8仅映射到值类型集合   java提供OSGi服务而不实现接口   java单个对象重写对象数组,不确定原因