Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get context of instance selector #19

Open
tbrlpld opened this issue Jun 2, 2021 · 4 comments
Open

Get context of instance selector #19

tbrlpld opened this issue Jun 2, 2021 · 4 comments

Comments

@tbrlpld
Copy link
Contributor

tbrlpld commented Jun 2, 2021

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.

@markfinger
Copy link
Contributor

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

@tbrlpld
Copy link
Contributor Author

tbrlpld commented Jun 3, 2021

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.

@markfinger
Copy link
Contributor

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.

@tbrlpld
Copy link
Contributor Author

tbrlpld commented Jun 7, 2021

Thanks @markfinger. I will do that 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants