Package: wagtailmodelchoosers
A Wagtail app to pick generic models (rather than snippets or pages).This is alpha software, use at your own risk. Do not use in production (yet).Check outAwesome Wagtailfor more awesome packages and resources from the Wagtail community.InstallationGrab the package from pip withpip install wagtailmodelchoosers, then addwagtailmodelchoosersinINSTALLED_APPSin your settings.UsageModelChooserBlocktakes the name of the chooser configuration as first positional argument. Use other block kwargs (e.g.required) as usual.fromwagtail.wagtailcoreimportblocksfromwagtailmodelchoosers.blocksimportModelChooserBlockclassCustomBlock(blocks.StructBlock):custom_model=ModelChooserBlock('custom_model')# `chooser` can be a positional argument, the keyword is used here for clarity.ModelChooserPaneltakes the name of the field as first positional argument (like a regular Panel) and the name of the chooser configuration as second positional argument. Use other panel kwargs as usual.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.]To select a model from a remote API, respectively useRemoteModelChooserBlockandRemoteModelChooserPanelinstead.If you haveWagtailDraftailinstalled, it will automatically register theModelSourceandRemoteModelSourceto the JS. Refer toWagtailDraftail’sdocumentationto hook it up properly.ConfigurationIt looks for aMODEL_CHOOSERS_OPTIONSdictionary in the settings where the key is the name of the chooser and the value, a dictionary of options.The ModelChooser and RemoteModelChooser share a similar base configuration and only have a few specific fields.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}}In addition, you can customise the mapping of the key of the API, see the configuration key names being used for thequeryand theresponse.DevelopmentInstallationRequirements:virtualenv,pyenv,twinegitclonegit@github.com:springload/wagtailmodelchoosers.gitcdwagtailmodelchoosers/virtualenv.venvsource./.venv/bin/activatepipinstall-e.[testing,docs]-UnvminstallnpminstallCommandsmakehelp# See what commands are available.TODO: CompleteReleasesMake a new branch for the release of the new version.Update theCHANGELOG.Update the version number inwagtailmodelchoosers/__init__.pyandpackage.json, following semver.Make a PR and squash merge it.Back on master with the PR merged, usemake publish(confirm, and enter your password).Finally, go to GitHub and create a release and a tag for the new version.Done!