Skip to content

Conversation

JaeHyuckSa
Copy link
Contributor

@JaeHyuckSa JaeHyuckSa commented Dec 2, 2024

Trac ticket number

ticket-34624

Branch description

I continued working on the PR for @allcaps.

Checklist

  • This PR targets the main branch.
  • The commit message is written in past tense, mentions the ticket number, and ends with a period.
  • I have checked the "Has patch" ticket flag in the Trac system.
  • I have added or updated relevant tests.
  • I have added or updated relevant docs, including release notes if applicable.
  • I have attached screenshots in both light and dark modes for any UI changes.

@BSmick6
Copy link
Contributor

BSmick6 commented Dec 2, 2024

@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

@JaeHyuckSa
Copy link
Contributor Author

@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

@BSmick6 Thank you for letting me know, but it seems that a different issue is occurring than the one you mentioned.

@BSmick6
Copy link
Contributor

BSmick6 commented Dec 3, 2024

@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

@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.

@sarahboyce
Copy link
Contributor

Instead of testing the redirect admin, I would refine a new admin in tests/admin_widgets/widgetadmin.py that sets radio_fields similar to the redirect admin

@JaeHyuckSa
Copy link
Contributor Author

@sarahboyce Thank you for the guidance. Sorry for the delayed response — I’ve updated the patch according to your feedback.

@sarahboyce sarahboyce added selenium Apply to have Selenium tests run on a PR screenshots 🖼️ labels Aug 26, 2025
Copy link
Contributor

@sarahboyce sarahboyce left a 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?

Comment on lines 289 to 294
# 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
Copy link
Contributor

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

Suggested change
# 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

Copy link
Contributor Author

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?

Copy link
Contributor

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 👍

@@ -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):
Copy link
Contributor

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)

Copy link
Contributor Author

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.

Copy link
Contributor

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

Copy link
Contributor Author

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.

@JaeHyuckSa
Copy link
Contributor Author

JaeHyuckSa commented Aug 26, 2025

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?

radio

image image

select widget

image image

@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?

@sarahboyce
Copy link
Contributor

Happy for it to be a select, a standard one is also fine imo.
I would have it as a seperate commit in this PR that is Refs #34624 --

@sarahboyce sarahboyce changed the title Fixed #34624 - Removed edit and view options in RelatedFieldWidgetWrapper for radioselects. Fixed #34624 -- Removed edit and view options in RelatedFieldWidgetWrapper for radioselects. Aug 28, 2025
…ct widgets in RelatedFieldWidgetWrapper.

Signed-off-by: SaJH <wogur981208@gmail.com>
…ite field.

Signed-off-by: SaJH <wogur981208@gmail.com>
@sarahboyce sarahboyce changed the title Fixed #34624 -- Removed edit and view options in RelatedFieldWidgetWrapper for radioselects. Fixed #34624 -- Removed change, delete, and view buttons for non-Select widgets in RelatedFieldWidgetWrapper. Aug 28, 2025
Copy link
Contributor

@sarahboyce sarahboyce left a 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

@sarahboyce sarahboyce merged commit eaaf01c into django:main Aug 29, 2025
34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
screenshots 🖼️ selenium Apply to have Selenium tests run on a PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants