-
-
Notifications
You must be signed in to change notification settings - Fork 32.9k
Fixed #34624 -- Removed change, delete, and view buttons for non-Select widgets in RelatedFieldWidgetWrapper. #18877
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
Conversation
2adf8a7
to
5785346
Compare
@JaeHyuckSa it looks like you're running into the same issue I was. You should rebase this branch to the main upstream branch and force push again: https://docs.djangoproject.com/en/5.1/internals/contributing/writing-code/working-with-git/#after-upstream-has-changed |
5785346
to
7770665
Compare
@BSmick6 Thank you for letting me know, but it seems that a different issue is occurring than the one you mentioned. |
Oh, interesting! I would love to find out why. I don't see why any of your changes would cause any of those errors, but I can try talking a look later this afternoon. |
Instead of testing the redirect admin, I would refine a new admin in |
7770665
to
242d790
Compare
@sarahboyce Thank you for the guidance. Sorry for the delayed response — I’ve updated the patch according to your feedback. |
3c4668a
to
4cdab7b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! I have a few suggestions
Note there is a second part of the ticket which is basically should RedirectAdmin
have radio_fields = {"site": admin.VERTICAL}
(using the AdminRadioSelect
widget) or should it use a select widget instead. Do you have thoughts on this?
django/contrib/admin/widgets.py
Outdated
# Widgets that display multiple values are not supported. | ||
supported = not getattr( | ||
widget, "allow_multiple_selected", False | ||
) and not isinstance(widget, AdminRadioSelect) | ||
self.can_change_related = supported and can_change_related |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe we should make this more generic
# Widgets that display multiple values are not supported. | |
supported = not getattr( | |
widget, "allow_multiple_selected", False | |
) and not isinstance(widget, AdminRadioSelect) | |
self.can_change_related = supported and can_change_related | |
# Only single-select Select widgets are supported. | |
supported = not getattr( | |
widget, "allow_multiple_selected", False | |
) and isinstance(widget, Select) |
You would need to add the import from django.forms.widgets import Select
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with making this more generic. Regarding your review, was the removal of line 293 intentional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No sorry that was a mistake in the comment 👍
tests/admin_widgets/tests.py
Outdated
@@ -2053,3 +2053,26 @@ def test_clearablefileinput_widget_preserve_clear_checkbox(self): | |||
self.selenium.find_element(By.ID, self.clear_checkbox_id).is_selected(), | |||
True, | |||
) | |||
|
|||
|
|||
class RadioFieldWidgetWrapperTests(AdminWidgetSeleniumTestCase): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of adding a selenium test (and models/admin), I would add the following test to RelatedFieldWidgetWrapperTests
def test_non_select_widget_cant_change_delete_related(self):
main_band = Event._meta.get_field("main_band")
widget = widgets.AdminRadioSelect()
wrapper = widgets.RelatedFieldWidgetWrapper(
widget,
main_band,
widget_admin_site,
can_add_related=True,
can_change_related=True,
can_delete_related=True,
)
self.assertTrue(wrapper.can_add_related)
self.assertFalse(wrapper.can_change_related)
self.assertFalse(wrapper.can_delete_related)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you the criteria for when to write a Selenium test versus a regular test? I think this will be more helpful for decision-making in future work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some things need a selenium test (e.g. if it was testing a mixture of python and javascript together or we want to generate screenshots). If it is possible to test with a regular test, this is usually preferable (especially if there are some existing ones) as they tend to be quicker to run
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the guidance.
radio![]() ![]() select widget![]() ![]() @sarahboyce Thank you for the review, Sarah. I had overlooked that there were additional considerations here. My view is that switching to a select (ideally autocomplete_fields) aligns better with the admin’s default patterns and the current JS behavior, while radios don’t scale well when there are many Sites, so I think moving to a select would be preferable. If the above is appropriate and changes are needed, would it be more suitable to continue in this PR, or should I open a separate PR for that work? |
Happy for it to be a select, a standard one is also fine imo. |
4cdab7b
to
be0fecb
Compare
…ct widgets in RelatedFieldWidgetWrapper. Signed-off-by: SaJH <wogur981208@gmail.com>
…ite field. Signed-off-by: SaJH <wogur981208@gmail.com>
be0fecb
to
12cd2b7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! This looks good to me
Trac ticket number
ticket-34624
Branch description
I continued working on the PR for @allcaps.
Checklist
main
branch.