from django.contrib.admin.models import User

115 views
Skip to first unread message

Bastian

unread,
Nov 5, 2012, 6:41:37 AM11/5/12
to django...@googlegroups.com
Hi,

When I need to use the 'User' class I always import it from django.contrib.auth.models. Now reading some code from other people sometimes I see it imported from django.contrib.admin.models and it seems to have the same consequences.
Can anybody tell me the difference between the two ways of importing 'User'?

Cheers!
Bastian

André Dieb

unread,
Nov 5, 2012, 6:50:23 AM11/5/12
to django...@googlegroups.com
From what I see on django's source code (dev), there used to be an import of django.contrib.auth.models.User inside django.contrib.admin.models, which means the answer to your question may be: there was no difference.

Though, probably best to use contrib.auth on any older version.



Bastian

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/aLj2wmpfr0oJ.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.



--
@andredieb

Russell Keith-Magee

unread,
Nov 5, 2012, 5:57:45 PM11/5/12
to django...@googlegroups.com
On Mon, Nov 5, 2012 at 7:50 PM, André Dieb <andre...@gmail.com> wrote:
From what I see on django's source code (dev), there used to be an import of django.contrib.auth.models.User inside django.contrib.admin.models, which means the answer to your question may be: there was no difference.

Incorrect - there *is* a difference. The import from admin is a side effect caused by admin's usage of the auth app; the auth import is the official location. As a result, the import from admin is not supported, and may be removed at any time without warning. Unless you like surprises, stick to the auth import.

Yours,
Russ Magee %-)


Bastian

unread,
Nov 6, 2012, 6:32:46 AM11/6/12
to django...@googlegroups.com
Thanks for your answers, I will stick with the official django.contrib.auth.models.

André Dieb

unread,
Nov 6, 2012, 6:55:41 AM11/6/12
to django...@googlegroups.com
To be honest I don't see how your answer differs from mine. I said the exact same thing :)

PS: right now there is no side-effect (no actual behaviour difference) from using User from admin, since it's originally . Though, I wouldn't recommend since it has already gone away on dev. code.

Yours,
Russ Magee %-)


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.


--
@andredieb

André Dieb

unread,
Nov 6, 2012, 7:13:48 AM11/6/12
to django...@googlegroups.com
On Tue, Nov 6, 2012 at 8:55 AM, André Dieb <andre...@gmail.com> wrote:
Em segunda-feira, 5 de novembro de 2012, Russell Keith-Magee escreveu:


On Mon, Nov 5, 2012 at 7:50 PM, André Dieb <andre...@gmail.com> wrote:
From what I see on django's source code (dev), there used to be an import of django.contrib.auth.models.User inside django.contrib.admin.models, which means the answer to your question may be: there was no difference.

Incorrect - there *is* a difference. The import from admin is a side effect caused by admin's usage of the auth app; the auth import is the official location. As a result, the import from admin is not supported, and may be removed at any time without warning. Unless you like surprises, stick to the auth import.

To be honest I don't see how your answer differs from mine. I said the exact same thing :)

PS: right now there is no side-effect (no actual behaviour difference) from using User from admin, since it's originally . Though, I wouldn't recommend since it has already gone away on dev. code.

Oops, sorry! My message was clipped.

From a purist POV who's not using django-dev right now, those modules are the same, though highly not recommended to use from admin as Russell noticed it may change in the future (as it already has).

Thanks!


Yours,
Russ Magee %-)


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.


--
@andredieb

Tom Evans

unread,
Nov 6, 2012, 7:49:26 AM11/6/12
to django...@googlegroups.com
On Tue, Nov 6, 2012 at 12:13 PM, André Dieb <andre...@gmail.com> wrote:
> On Tue, Nov 6, 2012 at 8:55 AM, André Dieb <andre...@gmail.com> wrote:
>>
>> Em segunda-feira, 5 de novembro de 2012, Russell Keith-Magee escreveu:
>>
>>>
>>> On Mon, Nov 5, 2012 at 7:50 PM, André Dieb <andre...@gmail.com> wrote:
>>>>
>>>> From what I see on django's source code (dev), there used to be an
>>>> import of django.contrib.auth.models.User inside
>>>> django.contrib.admin.models, which means the answer to your question may be:
>>>> there was no difference.
>>>>
>>> Incorrect - there *is* a difference. The import from admin is a side
>>> effect caused by admin's usage of the auth app; the auth import is the
>>> official location. As a result, the import from admin is not supported, and
>>> may be removed at any time without warning. Unless you like surprises, stick
>>> to the auth import.
>>
>>
>> To be honest I don't see how your answer differs from mine. I said the
>> exact same thing :)
>>
>> PS: right now there is no side-effect (no actual behaviour difference)
>> from using User from admin, since it's originally . Though, I wouldn't
>> recommend since it has already gone away on dev. code.
>
>
> Oops, sorry! My message was clipped.
>
> From a purist POV who's not using django-dev right now, those modules are
> the same, though highly not recommended to use from admin as Russell noticed
> it may change in the future (as it already has).
>
> Thanks!

They are not the same. The model is currently available from
django.contrib.admin.models only because that module is incorrectly
exporting symbols it itself has imported. If that was fixed, your code
would stop working.

Conclusion, don't rely on undocumented functionality, especially when
it only works due to happenstance.

Cheers

Tom
Reply all
Reply to author
Forward
0 new messages