#24689: DetailView get_template_name and get_context_object_name fail with 
deferred
QuerySet
---------------------------------+------------------------------------
     Reporter:  BertrandBordage  |                    Owner:  nobody
         Type:  Bug              |                   Status:  new
    Component:  Generic views    |                  Version:  master
     Severity:  Normal           |               Resolution:
     Keywords:                   |             Triage Stage:  Accepted
    Has patch:  1                |      Needs documentation:  0
  Needs tests:  1                |  Patch needs improvement:  0
Easy pickings:  0                |                    UI/UX:  0
---------------------------------+------------------------------------

Old description:

> Suppose you define a view like this:
>
> {{{
> from django.views.generic import DetailView
> from django.contrib.auth.models import User
>
> class UserDetail(DetailView):
>     model = User
>     queryset = User.objects.defer('password')
> }}}
>
> If you try to use the view, the default template name is
> {{{auth/user_deferred_password_detail.html}}} instead of
> {{{auth/user_detail.html}}}.
>
> This is because Django creates a proxy model each time you use
> defer/only. And therefore
> {{{User.objects.defer('password')[0]._meta.model_name}}} is
> {{{'user_deferred_password'}}}.
>
> {{{(DetailView|ListView).get_template_name}}} should ckeck if
> {{{model._deferred}}} and use {{{model._meta.proxy_for_model}}} to get
> the original model.

New description:

 Suppose you define a view like this:

 {{{
 from django.views.generic import DetailView
 from django.contrib.auth.models import User

 class UserDetail(DetailView):
     model = User
     queryset = User.objects.defer('password')
 }}}

 If you try to use the view, the default template name is
 {{{auth/user_deferred_password_detail.html}}} instead of
 {{{auth/user_detail.html}}}.

 This is because Django creates a proxy model each time you use defer/only.
 And therefore {{{User.objects.defer('password')[0]._meta.model_name}}} is
 {{{'user_deferred_password'}}}.

 {{{DetailView.get_template_name}}} should ckeck if {{{model._deferred}}}
 and use {{{model._meta.proxy_for_model}}} to get the original model.

--

Comment (by BertrandBordage):

 Indeed, it’s not occurring using ListView. I assumed it would occur on it
 because I thought {{{User.objects.defer('password')}}} would be a queryset
 of the proxy model {{{User_Deferred_password}}}, but it’s not. It’s only
 once you get model instances that they use the proxy model.

 Sorry for not checking :(

--
Ticket URL: <https://code.djangoproject.com/ticket/24689#comment:5>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" 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].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/073.39c914c98efb99bcdde7aed43b90e13b%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to