On Apr 22, 2013 7:15 AM, "Tom Christie" <christ...@gmail.com> wrote:
>
> 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.
I can think of a few reasons.
- you've changed models or fields internally through migrations, but need to continue supporting old URLs.
- you don't like the internal name to be exposed
- you have different models but want to expose a consistent URL pattern.
> 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 django-develop...@googlegroups.com.
> To post to this group, send email to django-d...@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-developers?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
I can think of a few reasons.
- you've changed models or fields internally through migrations, but need to continue supporting old URLs.
- you don't like the internal name to be exposed
- you have different models but want to expose a consistent URL pattern.