-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Allow ModelViewSet
to be used for models with non-integer primary keys
#10900
Allow ModelViewSet
to be used for models with non-integer primary keys
#10900
Conversation
Manage this branch in SquashTest this branch here: https://laymonagemodelviewset-non-inte-levys.squash.io |
"strid", | ||
models.CharField( | ||
primary_key=True, | ||
default=wagtail.test.testapp.models.random_quotable_pk, | ||
max_length=255, | ||
serialize=False, |
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.
Not sure if this should be in a new migration, I don't think it's worth it because the testapp is pretty much ephemeral and not intended to be long-lived. Properly migrating this would need more than one migration (to add the new field, populate, remove the old one).
We could start with a new model, but I intended this model to be the main model to test all ModelViewSet
features (hence "feature complete").
b249040
to
563df61
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.
All looks good to me!
In ModelViewSet, this doesn't do anything as the base ViewSet class returns an empty list. In SnippetViewSet, this causes the ModelViewSet's urlpatterns to be carried over, resulting in duplicate URLs that we do not want.
In case people hardcode the URLs instead of using reverse(). Unify the legacy redirects with SnippetViewSet to use the same _legacy_urlpatterns property.
563df61
to
ce8f655
Compare
wagtail/wagtail#10900 changed the default URL pattern for the edit view in ModelAdminViewset to place `/edit/` before the ID.
wagtail/wagtail#10900 changed the default URL pattern for the edit view in ModelAdminViewset to place `/edit/` before the ID.
wagtail/wagtail#10900 changed the default URL pattern for the edit view in ModelAdminViewset to place `/edit/` before the ID.
Similar fixes to #4166 and #7208.
To test:
I don't have a bakerydemo branch for this, but I've been using the testapp. You can configure this in the following:
DEBUG
inwagtail/test/settings.py
toTrue
(would love to change this in a separate PR)The server will run with the testapp configured. You can then use the Feature Complete Toy model to test the URLs. For testing the legacy redirects in
ModelViewSet
, you need to use a primary key string that's also a valid integer, as the old URL patterns use<int:pk>
.Please check the following:
make lint
from the Wagtail root.Footnotes
Development Testing ↩