Best Practice and documentation: from django.contrib.auth.models import User, Pylint and errors

Dear all,

Using VS Code I stumbled into this error raised by django-pyling:

Whenever I write:

from django.contrib.auth.models import User

Django-Pylint return me this error:

User model imported from django.contrib.auth.models

Apparently there are a lot of ppl experiencing the same errors on Stack Overflow (sorry can’t post url due to new user’s link limits)

and on Pylint repo, they also somehow criticize Django documentations, saying that the documentations contradict itselfs and

FTR Django doesn't always document or even follow its practices.

I am wondering:

I am referring and using Django 4

Thanks for clarification!

Django does say to use get_user_model()only when building reusable apps - i.e. those intended for use in multiple projects, installed via PyPI or similar.

This is covered under the heading Reusable apps and AUTH_USER_MODEL in the docs.

pylint-django is somewhat mistaken in always recommending this. If you are building a normal Django project you do not need to use get_user_model().

The Django docs could perhaps be reworded to reiterate this.

Edit: Opened an issue in pylint-django to modify the check.


thank you @adamchainz
loved your precision and your effort in helping me understand what’s the right use of Django!

I’m going to toss in an additional thought here, too.

When we want to extend User, we rely upon the User Profile pattern. (See the second paragraph at Extending the existing User model.)

Of the dozen or so Django applications I manage, only one changes the User model - and about half the time I regret that decision. In all other cases, one (or more) profile models are used to store related information about a user.

(I’m actually of the belief that the current User model is already too bloated and would be improved if it were slimmed down even farther.)

1 Like