Opened 11 years ago
Last modified 5 years ago
#22724 new Cleanup/optimization
Improve SingleObjectMixin
| Reported by: | tomc | Owned by: | |
|---|---|---|---|
| Component: | Generic views | Version: | dev |
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Accepted | |
| Has patch: | yes | Needs documentation: | yes |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
Belatedly following on from https://code.djangoproject.com/ticket/21898
I feel that slug_url_kwarg and pk_url_kwarg don't feel very in keeping with the rest of django to me, and some thought could be put into improving this part of the API.
My personal opinion is that I don't think that SingleObjectMixin should require a pk, slug, or these variables to be set if you provide a queryset of your own. I don't see any reason why we shouldn't have a DetailView without any arguments in the URL at all, if we provide a single object in some manner. At the moment to do this, we have to override get_object() and essentially rewrite it, which does not feel very elegant to me.
Change History (10)
comment:1 by , 11 years ago
| Cc: | added |
|---|
comment:2 by , 11 years ago
| Triage Stage: | Unreviewed → Accepted |
|---|
comment:3 by , 11 years ago
| Has patch: | set |
|---|---|
| Owner: | changed from to |
| Status: | new → assigned |
Created pull request:
comment:4 by , 11 years ago
| Needs documentation: | set |
|---|---|
| Needs tests: | set |
Needs tests and (probably) documentation.
comment:5 by , 11 years ago
Tests have been provided by msoedov.
https://github.com/django/django/pull/2863
I'm unsure if there's any documentation that needs to be updated... Couldn't find any at a first quick glance, but I could have missed something.
comment:6 by , 11 years ago
| Needs tests: | unset |
|---|
comment:7 by , 11 years ago
The documentation to be updated is located here. Be sure to annotate the changes with .. versionchanged:: 1.8 and also mention it in the release notes. It would also be helpful to describe this better than "Improve SingleObjectMixin." in the ticket & commit message.
comment:8 by , 11 years ago
Proposed patch was significantly backwards incompatible (see my comments on the PR). It however should be possible to refactor get_object itself to make a better subclassing experience, possibly by adding an inner get_from_queryset method, or by changing the behaviour when no slug or pk is provided.
comment:9 by , 11 years ago
| Cc: | removed |
|---|
comment:10 by , 5 years ago
| Owner: | removed |
|---|---|
| Status: | assigned → new |
Accepting per mjtamlyn's comment on #21898.