question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Generic ModelChooserBlock for StreamField

See original GitHub issue

I’d like to propose a ForeignBlock or similar using models.ForeignKey as it’s base for allowing integrations with other model clusters/models. It would most likely need to extend blocks.ChooserBlock and shouldn’t be too difficult.

Issue Analytics

  • State:open
  • Created 8 years ago
  • Reactions:13
  • Comments:13 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
m1kolacommented, Nov 23, 2017

Currently there are two ways to manage non-Page models in Wagtail:

When you register your model as a snippet it allows you to edit objects through the Admin -> Snippets -> Your snippet name menu and use nice chooser UI in the editing interface.

However there are few cases when this behaviour doesn’t work really well:

  • When you need fairly complex admin UI (with filters, for example) and have the chooser UI. In this case, most likely you would decide to use Model Admin, but Model Admin doesn’t allow you to use the chooser UI. There is a workaround: you can register your model as a snippet alongside with Model Admin UI. As a result you will have two places to edit snippet: one in the Admin -> Snippets -> Your snippet name and one in the Model Admin UI which is confusing. Generic model chooser should solve this issue.
  • When you need to have the chooser UI for snippets that do not need editing (data imported from some API, for example).

Taking into account the last point, it seems to me that the generic model chooser must not rely on Model Admin. I think, it should be something like the existing register_snippet but without exposing editing UI.

1reaction
ababiccommented, Jul 5, 2016

I think the blocker to having a ModelAdmin-based chooser has been: ModelAdmin classes/instances know about the model they represent, but there’s no easy way to access a ModelAdmin class/instance from a model. Without moving to a ‘django-like’ registration method, where the relationships between models and ModelAdmin classes are stored in a central/reference-able place, I don’t see how we can circumvent this. But that has a tonne of other implications that need thinking through. That’s maybe a discussion for the developers board though, rather than here.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Developers - Generic ModelChooserBlock for StreamField -
I'd like to propose a ForeignBlock or similar using models.ForeignKey as it's base for allowing integrations with other model clusters/models.
Read more >
How to use StreamField for mixed content
In addition to using the built-in block types directly within StreamField, it's possible to construct new block types by combining sub-blocks in various...
Read more >
wagtail-modelchooser - PyPI
A plugin for Wagtail that provides a ModelChooserPanel and ModelChooserBlock for arbitrary models. Installing. Install using pip:
Read more >
How to Add a Basic StreamField to your Wagtail CMS Page
Tutorial Summary. In this lesson we are going to learn how to add a basic StreamField to a a generic Wagtail CMS Page....
Read more >
How to Add a Basic StreamField to your Wagtail CMS Page
In this lesson we are going to learn how to add a basic StreamField to a a generic Wagtail CMS Page. We'll create...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found