Open tbrlpld opened 3 years ago
I don't think there's a built-in or easy way to do it.
I think the best approach would be to modify the widget's rendering to add an extra parameter onto the model-admin's url, then modify your model admin's index view to use the value in the param.
Kinda related: #7
Thanks @markfinger.
Do you have a pointer on how the widget would get access to the context of the page that is being edited? I am assuming that the page edit interface is a Django edit view... not sure if that is correct.
I have a vague memory of looking into something similar a year or two back and found that the usual APIs for Wagtail's forms only provide minimal data to the widgets (eg: only a field's value, not the root object itself). That being said, I wouldn't be surprised if there's some undocumented method that could be used.
Might be worth asking in the Wagtail Slack how to get access to the root object (eg: a page or other model instance) from a content panel.
Thanks @markfinger. I will do that 👍
Not an issue, just a question:
I was wondering if there is a way to get the context in which the instance selector panel/modal is opened?
In my use case I would like to filter the instances displayed in the admin based on the current page in which the selector panel is opened. The model admin already comes with the filtering ability. All I would need from the context is the current pages id so that I can use that in the selectors
get_instance_selector_url
.