I'd be interested to know what you folks think of this proposal.
SingleObjectMixin currently exposes these three attributes and one method
all dealing with queryset filter arguments...
* pk_url_kwarg = 'pk'
* slug_field = 'slug'
* slug_url_kwarg = 'slug'
* get_slug_field()
I was wondering if it would be worth considering simplifying the API
somewhat, by moving those three attributes, and that method, into a
PendingDeprecation state, and replacing their usage with a single attribute
instead, that is used both as the URL kwarg, and as the queryset filter.
* lookup_field = 'pk'
That'd (eventually) lead to a simpler get_object implementation internally,
and (immediately) present a slightly nicer, simpler API.
It'd be marginally different in that slug based lookups would require an
explicit `lookup_field = 'slug'` to be added to the view,
and also in that it wouldn't handle the case of `slug_field` being set to a
different value from `slug_url_kwarg`.
Personally I don't see the later being an issue as:
1. It's not clear to me why you'd ever *need* to use a URL kwarg that's not
the same as the filter arg.
2. If it's really something you need to do, then overriding get_object is
still really simple, as well as being nice and explicit...
get_object(self, queryset):
if queryset is None:
queryset = self.get_queryset()
return get_object_or_404(queryset, ...) # whatever custom lookup
behavior you need.
To me, the main trade-off seems to be - Is the resulting API enough of an
improvement to be worth the change?
Any opinions?
Tom
As an aside, is the discussion group considered the correct place for
API-changing proposals like this, or should I just raise them straight to
the ticket tracker?
--
You received this message because you are subscribed to the Google Groups
"Django developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-developers?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.