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

MultipleChooserPanel should not allow selecting duplicate objects #10496

Open
pySilver opened this issue May 31, 2023 · 6 comments · May be fixed by #11855
Open

MultipleChooserPanel should not allow selecting duplicate objects #10496

pySilver opened this issue May 31, 2023 · 6 comments · May be fixed by #11855
Labels
component:Choosers Modal choosers for Page, Snippet and other models component:Panels type:Enhancement

Comments

@pySilver
Copy link
Contributor

Issue Summary

it looks like MultipleChooserPanel allows selecting the same objects when accessed multiple times. Yes, it shows an appropriate error message on save but such behavior should not be possible in the first place or at least configurable.

@pySilver pySilver added status:Unconfirmed Issue, usually a bug, that has not yet been validated as a confirmed problem. type:Bug labels May 31, 2023
@gasman
Copy link
Collaborator

gasman commented May 31, 2023

Thanks for the suggestion @pySilver! This isn't something that we'd want to "bake in" to MultipleChooserPanel, since we don't want it to be limited to plain many-to-many relations - it needs to cover cases such as a slideshow where each slide is an image plus caption, and choosing an image once should not prevent using it again (with another caption).

I suppose the neatest approach here would be for MultipleChooserPanel to recognise when the inline child model has a unique_together constraint over the ForeignKey field named in chooser_field_name and the ParentalKey pointing back to the page (or snippet), and preventing duplicate selections in that case. Even then, there would probably be a lot of work involved on the UI side to make the chooser popup a true reflection of the current selected state (e.g. showing the already-selected items and persisting them when filtering/paginating) rather than just a mechanism for selecting new ones.

@gasman gasman added type:Enhancement component:Panels component:Choosers Modal choosers for Page, Snippet and other models and removed type:Bug status:Unconfirmed Issue, usually a bug, that has not yet been validated as a confirmed problem. labels May 31, 2023
@pySilver
Copy link
Contributor Author

Good point. State issues :) What about passing the selection state back to the modal every time it's requested and handle unique optional requirement there.

@TonisPiip
Copy link

I am also facing this issue, and ask if there is some known way to pass in a QS of options into the MultipleChooserPanel so that the choices in the modal are limited with some logic, either by unique to what's already saved in the model, or some other logic.

@TonisPiip
Copy link

It seems that currently the most sane solution would be to get the reffer header from the request, and use that to reverse the url, get the object which is being edited, and then filter the QS based on that. IT doesn't include the current form state, but works well when adding a extra item to a unique list, as it'll only show valid non-duplciate rows.

@gasman
Copy link
Collaborator

gasman commented Oct 5, 2023

The referer header is not reliable - browsers often block it for privacy reasons. However, passing a list of currently-selected object IDs to the chooser is not really the hard part - the hard part is keeping track of the currently selected items while navigating through the chooser.

@TonisPiip
Copy link

currently selected items

Meaning: the current state of the model Form?

or

The currently edited object ID, is hard to track when navigating?

Even having the currently edited object in the request, would be a massive improvement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component:Choosers Modal choosers for Page, Snippet and other models component:Panels type:Enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants