wagtail / wagtail-generic-chooser

A toolkit for custom chooser popups in Wagtail
BSD 3-Clause "New" or "Revised" License
116 stars 25 forks source link

Extend wagtail ChooserBlock for and API not a model #46

Closed MoRadwan74 closed 2 years ago

MoRadwan74 commented 2 years ago

Hello there,

I want to extend the ChooserBlock model not with a target_model, but with an JSON object returned from an DRF-based API request. Simply, I have a list of JSON objects that I want to be able to add it to the ChooserBlock and the user is able to select one of them in wagtail admin.

Can this package provide me this? It was promising when I read this line in the README:

It differs from existing model chooser add-ons (Naeka/wagtailmodelchooser, neon-jungle/wagtailmodelchooser, springload/wagtailmodelchoosers) in that it is designed to be fully configurable through subclassing - in particular, it can be used on data sources other than Django models, such as REST API endpoints.

But I got lost between the views and widgets here as it seems this package is intended to control the DRF API provided by wagtail and not an external REST API endpoint as mentioned in the quote above.

Any help would be very appreciated.

gasman commented 2 years ago

wagtail-generic-chooser doesn't currently provide any mechanism for this, no. The base ChooserBlock implementation provided by Wagtail defines various data conversions that only make sense for Django models - e.g. to turn the ID as stored in the streamfield's JSON representation into an object it's possible to use target_model.objects.get(pk=...). For a REST API endpoint, you'd need to come up with new definitions for these data conversions. It ought to be possible to do this by subclassing FieldBlock, but this process isn't well-documented at the moment.

MoRadwan74 commented 2 years ago

Okay, thanks for the info, @gasman. I will close this one.