选择通用模型(而不是代码片段或页面)的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实现的一个简单算法(计算概率)   更改应用程序背景动画的java首选项   java捕获图像并通过socket发送   基于双精度数组的对象的java排序Arraylist?   java似乎无法获得前面数字的正确总和   java卡住了Tomcat线程。日食乐观锁定   java是一个异步的Throwable类的printStackTrace()   java随机错误(可能是)Android支持库   java我应该在代码中自动创建DB表,还是在安装过程中使用preinit?   在被调用的方法/函数Java/Android中处理异常?   arraylist Java发送电子邮件非法分号?   while循环中的Java数组   java Arquillian和TransactionAttribute类型。需要新的   java“未找到合适的驱动程序”获取此错误   java高性能地将子类转换为真正的超类   java如何从另一个活动访问变量   安卓 Java Kotlin泛型将类getter作为参数传递到函数中   尝试访问数组的某个位置时需要java“]”