📜 ⬆️ ⬇️

In django, you can use your model instead of contrib.auth.models.User

image

Six years after the appearance of the ticket with the possibility of using its model instead of the standard django.contrib.auth.models.User and thousands of posts with the ideas of using the additional profile model, a miracle happened: https://github.com/django/django/commit/70a0de37d132e5f1514fb9398ff64649f


')
Now the user model is specified in the project settings:

AUTH_USER_MODEL = 'auth.User' 


And to create a ForeignKey for a user model, they suggest using the following method:

 user = models.ForeignKey(settings.AUTH_USER_MODEL) 


In this case, it is recommended to consider separately the need to store all user information not related to authorization in one model. Perhaps the best way to store such data would be the good old way with additional models; This will allow each application to have its own user information without the risk of conflicts with other applications.

The rest of the documentation on the new functionality is already on the site: docs.djangoproject.com/en/dev/topics/auth/#customizing-the-user-model

Those who can't wait to try out the long-awaited feature in action can already use the trunk repository, while stability lovers will have to wait for django 1.5 to be released.

Source: https://habr.com/ru/post/152603/


All Articles