Recently I've implemented a ChooserViewSet for a custom StreamField ImageChooserBlock
, and came across a gotcha that had me stumped for a while.
On the whole I find the latest ViewSets setup pretty neat, however, although the register_admin_viewset
hook is referenced in this part of the docs, it's not currently documented in hooks, so it's not clear exactly what this hook does.
Anyway, the concept was sound - implement a ViewSet
to restrict image choices to a "Logos" collection, and set the choose/edit text to something more precise, e.g. "Choose a logo", "Edit this logo" etc.
All well and good, until realising that now all image choosers across the site admin had this behaviour.
:scream
At first, I thought I'd need to filter by the request or something similar, but that's not possible from what I could tell.
Finally, I found the magic word.
On the ChooserViewSet
class, make sure to set the following property:
register_widget = False
This will restrict the view set to just the places where you intend to implement it, and will save you a ton of head-scratching slash hair-pulling.