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.
--
Ticket URL: <https://code.djangoproject.com/ticket/22724>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* cc: maxime.turcotte@… (added)
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/22724#comment:1>
* stage: Unreviewed => Accepted
Comment:
Accepting per mjtamlyn's comment on #21898.
--
Ticket URL: <https://code.djangoproject.com/ticket/22724#comment:2>
* owner: nobody => msoedov
* status: new => assigned
* has_patch: 0 => 1
Comment:
Created pull request:
https://github.com/django/django/pull/2863
--
Ticket URL: <https://code.djangoproject.com/ticket/22724#comment:3>
* needs_docs: 0 => 1
* needs_tests: 0 => 1
Comment:
Needs tests and (probably) documentation.
--
Ticket URL: <https://code.djangoproject.com/ticket/22724#comment:4>
Comment (by dbrgn):
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.
--
Ticket URL: <https://code.djangoproject.com/ticket/22724#comment:5>
* needs_tests: 1 => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/22724#comment:6>
Comment (by timo):
The documentation to be updated is located
[https://docs.djangoproject.com/en/dev/ref/class-based-views/mixins-
single-object/ 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.
--
Ticket URL: <https://code.djangoproject.com/ticket/22724#comment:7>
Comment (by mjtamlyn):
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.
--
Ticket URL: <https://code.djangoproject.com/ticket/22724#comment:8>
* cc: maxime.turcotte@… (removed)
--
Ticket URL: <https://code.djangoproject.com/ticket/22724#comment:9>
* owner: Alex Myasoedov => (none)
* status: assigned => new
--
Ticket URL: <https://code.djangoproject.com/ticket/22724#comment:10>