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

Move SnippetViewSet.get_edit_handler() to ModelViewSet #10830

Merged
merged 4 commits into from
Nov 28, 2023

Conversation

laymonage
Copy link
Member

@laymonage laymonage commented Aug 24, 2023

Part of #10740. This allows using the Panels mechanism to render the form for ModelViewSet by defining panels or edit_handler on the ModelViewSet or model class.

One difference from SnippetViewSet is that ModelViewSet does not fall back to extracting the panel definitions from the model class if neither panels nor edit_handler is defined, and instead will fall back to the original behaviour of requiring either form_fields, exclude_form_fields, or overriding get_form_class.

To test, you can use my bakerydemo branch where the Country model has been configured to use a ModelViewSet with panels.

When reviewing, hide whitespace to get better diffs.

Please check the following:

  • Do the tests still pass?1
  • Does the code comply with the style guide?
    • Run make lint from the Wagtail root.
  • For Python changes: Have you added tests to cover the new/fixed behaviour?
  • For new features: Has the documentation been updated accordingly?

Footnotes

  1. Development Testing

@squash-labs
Copy link

squash-labs bot commented Aug 24, 2023

Manage this branch in Squash

Test this branch here: https://laymonagemodelviewset-edit-han-je9ic.squash.io

@laymonage laymonage self-assigned this Aug 29, 2023
@laymonage laymonage added this to the 5.2 milestone Aug 30, 2023
@gasman gasman modified the milestones: 5.2, 5.3 Oct 13, 2023
@laymonage laymonage force-pushed the modelviewset-edit-handler branch 2 times, most recently from 2159bfc to be8f10a Compare November 7, 2023 16:40
@laymonage laymonage force-pushed the modelviewset-edit-handler branch 2 times, most recently from 14611ea to d897573 Compare November 13, 2023 09:11
@laymonage laymonage marked this pull request as ready for review November 13, 2023 09:21
Copy link
Collaborator

@gasman gasman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

However, keep the logic for falling back to extracting panel definitions
from the model class as snippets-specific. ModelViewSets are likely used
with models that are more low-level and thus we want developers to
explicitly define the fields that are editable in the admin, just like
how Django's ModelForm works.
@laymonage laymonage merged commit 3891677 into wagtail:main Nov 28, 2023
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

2 participants