-
-
Notifications
You must be signed in to change notification settings - Fork 33.1k
Fixed #36187 -- Added support for CompositePrimaryKey in SingleObjectMixin. #19767
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
base: main
Are you sure you want to change the base?
Conversation
ba30c70
to
2957a43
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.
Thanks @JaeHyuckSa for picking this up!
I left some comments inline; let me know what you think
19b1109
to
425e743
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.
Thanks 👍🏾 @JaeHyuckSa for the updates!
a17ae6c
to
2ea01e6
Compare
…Mixin. Signed-off-by: SaJH <[email protected]>
2ea01e6
to
e356068
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.
Thanks @JaeHyuckSa 👍 I think this is really close.
_("No %(verbose_name)s found matching the query") | ||
% {"verbose_name": queryset.model._meta.verbose_name} | ||
) | ||
|
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.
A merger or someone will tell if we need to update the error on L64 to mention primary key fields.
For models with a composite primary key, ``get_object()`` will | ||
look for all primary key field names (as defined in ``pk_fields``) | ||
in the keyword arguments. If all are present, it performs a get | ||
lookup with those values. If any are missing, it returns a 404. |
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.
It only returns a 404 if the pk_fields are all present but the lookup does not return an object. If they aren't, it raises an attribute error, the one mentioned in my previous comment.
Additionally, please add an :attr:
ref to pk_fiekds
an example. | ||
|
||
|
||
Composite primary keys with Class-Based Views |
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.
Composite primary keys with Class-Based Views | |
Models with composite primary keys |
(Maybe. Also, use sentence-casw for headings)
|
||
All field names from :attr:`~django.db.models.options.Options.pk_fields` | ||
must be present as URL parameters. No comma separators or specific ordering | ||
required. |
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 need for a paragraph break, here
required. | ||
|
||
In other words, the following URLconfs would have worked as well when | ||
fetching composite-pk models: |
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 think this needs to have two colons ::
In other words, the following URLconfs would have worked as well when | ||
fetching composite-pk models: | ||
|
||
path("item/<int:product_id>/<str:order_id>/", |
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.
This is the same as what we used in the example
Trac ticket number
ticket-36187
Checklist
main
branch.