diff --git a/antipattern/refer-to-the-user-model-directly.md b/antipattern/refer-to-the-user-model-directly.md index 0cb629b..56c558c 100644 --- a/antipattern/refer-to-the-user-model-directly.md +++ b/antipattern/refer-to-the-user-model-directly.md @@ -23,7 +23,7 @@ class Post(models.Model): # Why is it a problem? -One does not per se needs to use Django's `User` model. It is possible that one +One does not per se need to use Django's `User` model. It is possible that one now sticks to Django's default `User` model, but later one defines a [*custom user model*](https://docs.djangoproject.com/en/3.1/topics/auth/customizing/#specifying-a-custom-user-model), then one has to change all `ForeignKey`s, which is cumbersome, and error-prone. @@ -37,11 +37,11 @@ we *reference* that model. This thus makes the project less flexible. We can make use of the [**`AUTH_USER_MODEL`** setting [Django-doc]](https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-AUTH_USER_MODEL). This is a string setting that contains the app_name.ModelName of the -user model that is in use. Django thus will thus construct a `ForeignKey` with a +user model that is in use. Django will thus construct a `ForeignKey` with a string as target. This target is then, when all apps are loaded, resolved to the corresponding model. -We thus can thus let the `ForeignKey` reference the value of the +We can thus let the `ForeignKey` reference the value of the `AUTH_USER_MODEL` setting:
from django.conf import settings