﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
20294	Problem with generic views when the model is called 'User'.	ttt@…	Zbigniew Siciarz	"= Context =

I have extended the Django User model in order to have a customized authentication.
And my model class is also called 'User'.
I am successfully using generic views default configuration for all models except for the 'User'.

According to the documentation, the context variable will be inferred from the model name.
But there seems to be an extra context variable called user, that is always present and provides information about the authenticated user, for which I could not find mention in the documentation of 1.5, but is described in 1.2 docs here:
https://docs.djangoproject.com/en/1.2/topics/auth/#authentication-data-in-templates

= Problem =

The following code does not work as expected:

 * urls.py
{{{
...
    url(r'^user/(?P<pk>\d+)/$', DetailView.as_view( model = User ), name = 'user'),
...
}}}

 * user_detail.html
{{{
{% if user %}
    <p>id                    : {{ user.id                    }}</p>
    <p>name                  : {{ user.name                  }}</p>
    <p>description           : {{ user.description           }}</p>
    <p>email                 : {{ user.email                 }}</p>
...
}}}

Instead of getting the details for the user with the corresponding pk (user.id) is present in the URL, the authenticated user details are always returned.
There is no warning in the logs about the override, of the user object retrieved from the database, by the authenticated user object within the template context variables namespace.

= Workaround =

The desired behavior is obtained after changing the context object name from the default 'user' to 'u', as follows:

 * urls.py
{{{
...
    url(r'^user/(?P<pk>\d+)/$', DetailView.as_view( model = User, context_object_name = 'u' ), name = 'user'),
...
}}}

 * user_detail.html
{{{
{% if u %}
    <p>id                    : {{ u.id                    }}</p>
    <p>name                  : {{ u.name                  }}</p>
    <p>description           : {{ u.description           }}</p>
    <p>email                 : {{ u.email                 }}</p>
...
}}}

This way I can obtain the details for any given user, by id.

"	Uncategorized	closed	Documentation	1.5	Normal	fixed	user generic views context variable		Accepted	0	0	0	0	0	0
