ixc / wagtail-instance-selector

A widget for Wagtail's admin that allows you to create and select related items
MIT License
54 stars 17 forks source link

Is there any way to define queryset in InstanceSelectorBlock #7

Open mubarak117136 opened 4 years ago

mubarak117136 commented 4 years ago

hi, i am trouble with a issue where i must need to use queryset in InstanceSelectorBlock.

class ProductBlock(InstanceSelectorBlock):
    def __init__(self, *args, **kwargs):
        target_model = kwargs.pop("target_model", "store.Product")
        super(ProductBlock, self).__init__(target_model=target_model, **kwargs)

Is there any way to initialize InstanceSelectorBlock with queryset.

thanks

markfinger commented 4 years ago

Hi,

Not trivially. I think you'd need to punch through a few layers and configure a GET param in the url of the embed so your modeladmin could change the queryset.

Off the top of my head, you'd probably need to override widget on the InstanceSelectorBlock subclass, and provide your own InstanceSelectorWidget subclass that appends a param to the embed's url.

This seems like a pretty reasonable use-case. If you get it working, it'd be great if you could either paste some code here or even open a PR.