Opened 10 years ago

Last modified 10 years ago

#24689 closed Bug

DetailView & ListView get_template_name fails with deferred QuerySet — at Initial Version

Reported by: Bertrand Bordage Owned by: nobody
Component: Generic views Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: no
Easy pickings: no UI/UX: no

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.

Change History (0)

Note: See TracTickets for help on using tickets.
Back to Top